Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
jeff_sawatzky
Posts: 29
Registered: ‎04-01-2013
My Device: Z10

window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

I have the following code:

window.resolveLocalFileSystemURI(
    params.file.fileuri,
    function (fileInfo) {
        // Do something with the fileInfo
    },
    function (error) {
        console.error("Unable to resolve Local File System URI: " + params.file.fileuri);
        console.error(error);
    }
);

 

My error callback is always getting called, and outputting a message similar to:

Unable to resolve Local File System URI: file:///accounts/1000/shared/camera/IMG_00000037.jpg

 

I am using PhoneGap (2.5.0). I am pretty sure I have enabled all the features/permissions in my config:

<!-- Cordova API -->
<feature id="blackberry.system" required="true" version="1.0.0.0" />
<feature id="org.apache.cordova" required="true" version="1.0.0" />
<feature id="blackberry.find" required="true" version="1.0.0.0" />
<feature id="blackberry.identity" required="true" version="1.0.0.0" />
<feature id="blackberry.identity.phone" required="true" version="1.0.0.0" />
<feature id="blackberry.pim.Address" required="true" version="1.0.0.0" />
<feature id="blackberry.pim.Contact" required="true" version="1.0.0.0" />
<feature id="blackberry.io.file" required="true" version="1.0.0.0" />
<feature id="blackberry.utils" required="true" version="1.0.0.0" />
<feature id="blackberry.io.dir" required="true" version="1.0.0.0" />
<feature id="blackberry.app" required="true" version="1.0.0.0" />
<feature id="blackberry.app.event" required="true" version="1.0.0.0" />
<feature id="blackberry.system.event" required="true" version="1.0.0.0"/>
<feature id="blackberry.widgetcache" required="true" version="1.0.0.0"/>
<feature id="blackberry.media.camera" />
<feature id="blackberry.ui.dialog" />
<feature id="blackberry.connection" />
<feature id="blackberry.bbm.platform" />
<feature id="blackberry.invoke.card" />
<feature id="blackberry.pim.contacts" />
<feature id="blackberry.ui.contextmenu" />
<feature id="blackberry.io.filetransfer" />
<feature id="blackberry.io" />
<feature id="blackberry.invoke" />
<feature id="blackberry.invoked" />
<feature id="blackberry.push" />
<feature id="blackberry.media.microphone" required="true" version="1.0.0.0"/>

 

<rim:smileytongue:ermissions>
  <rim:smileytongue:ermit>use_camera</rim:smileytongue:ermit>
  <rim:smileytongue:ermit>read_device_identifying_information</rim:smileytongue:ermit>
  <rim:smileytongue:ermit>access_shared</rim:smileytongue:ermit>
  <rim:smileytongue:ermit>read_geolocation</rim:smileytongue:ermit>
  <rim:smileytongue:ermit>record_audio</rim:smileytongue:ermit>
  <rim:smileytongue:ermit>access_pimdomain_contacts</rim:smileytongue:ermit>
</rim:smileytongue:ermissions>

 

What am I missing?

Please use plain text.
Developer
jeff_sawatzky
Posts: 29
Registered: ‎04-01-2013
My Device: Z10

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

Forgot to mention that I am debugging on a Z10
Please use plain text.
Developer
jeff_sawatzky
Posts: 29
Registered: ‎04-01-2013
My Device: Z10

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

Here is a small example to reproduce the issue:

<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<title>Hello World</title>

&lt;script type="text/javascript" charset="utf-8">

// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
// Uncomment to view the image file URI
console.log(imageURI);

// Get image handle
//
var image = document.getElementById('image');

// Unhide image elements
//
image.style.display = 'block';

// Show the captured photo
// The inline CSS rules are used to resize the image
//
image.src=imageURI;

window.resolveLocalFileSystemURI(
imageURI,
function (fileInfo) {
console.debug("Resolved local file system URI: " + imageURI);
console.debug(fileInfo);
},
function (error) {
console.error("Unable to resolve local file system URI: " + imageURI);
console.error(error);
}
);
}

// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}

// A button will call this function
//
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(
onPhotoURISuccess,
onFail,
{
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: source,
correctOrientation: true,
saveToPhotoAlbum: true
}
);
}
&lt;/script&gt;

</head>
<body>
&lt;script type="text/javascript" src="cordova-2.5.0.js">&lt;/script&gt;
<button onclick="getPhoto(Camera.PictureSourceType.CAMERA);">Capture Photo</button>
<br>
<img style="display:none;" id="image" width="100" height="100" src="" />
</body>
</html>
Please use plain text.
Contributor
kdart89
Posts: 10
Registered: ‎03-26-2013
My Device: BlackBerry Z10

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

I am also having this problem - I have also noticed that the Camera.DestinationType.DATA_URL is meant to return a base64 encoded string, however on BlackBerry OS10 this also returns a File URI.

 

I need to do something similar with regards to uploading an image (I send it as a JSON encoded string due to different requirements). However, with both the FILE_URI not resolving to a FileEntry; and DATA_URL not returning the base64 encoded string as I was expecting, I have no way to get get the phsyical image file object in order to resolve it.

 

Has anyone had any success with this? And if so, how?! For those who want to look at my config.xml file, then it is as follows (apologies for hijacking the thread - I just wanted to add my config.xml file to show what permissions my app has - which I've temporarily disabled web security for testing purposes and allowed access to all URIs just to eliminate the possibility of permissions causing a problem):

 

<?xml version="1.0" encoding="UTF-8"?>
<!-- 
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
-->
<!--
  Widget Configuration Reference:
    http://docs.blackberry.com/en/developers/deliverables/15274/
-->

<widget xmlns="http://www.w3.org/ns/widgets"
        xmlns:rim="http://www.blackberry.com/ns/widgets"
	version="1.0.1.2" id="com.app.myapp">

  <name>MyApp</name>

  <author>kdart89</author>

  <description>
       MyApp for demonstration purposes
  </description>
    
  <license href="http://opensource.org/licenses/alphabetical">
  </license>

  <!-- Cordova API -->
  <feature id="blackberry.system" required="true" version="1.0.0.0" />
  <feature id="org.apache.cordova" required="true" version="1.0.0" />
  <feature id="blackberry.find" required="true" version="1.0.0.0" />
  <feature id="blackberry.identity" required="true" version="1.0.0.0" />
  <feature id="blackberry.identity.phone" required="true" version="1.0.0.0" />
  <feature id="blackberry.pim.Address" required="true" version="1.0.0.0" />
  <feature id="blackberry.pim.Contact" required="true" version="1.0.0.0" />
  <feature id="blackberry.io.file" required="true" version="1.0.0.0" />
  <feature id="blackberry.utils" required="true" version="1.0.0.0" />
  <feature id="blackberry.io.dir" required="true" version="1.0.0.0" />
  <feature id="blackberry.app" required="true" version="1.0.0.0" />
  <feature id="blackberry.app.event" required="true" version="1.0.0.0" />
  <feature id="blackberry.system.event" required="true" version="1.0.0.0"/>
  <feature id="blackberry.widgetcache" required="true" version="1.0.0.0"/>
  <feature id="blackberry.media.camera" />
  <feature id="blackberry.ui.dialog" />
  <feature id="blackberry.connection" />
  <feature id="blackberry.bbm.platform" />
  <feature id="blackberry.invoke.card" />
  <feature id="blackberry.pim.contacts" />
  <feature id="blackberry.ui.contextmenu" />
  <feature id="blackberry.io.filetransfer" />
  <feature id="blackberry.io" />
  <feature id="blackberry.invoke" />
  <feature id="blackberry.invoked" />
  <feature id="blackberry.push" />
  <feature id="blackberry.media.microphone" required="true" version="1.0.0.0"/>
  
  <!-- remove this to tighten security -->
  <feature id="blackberry.app" required="true" >
    <param name="websecurity" value="disable" version="1.0.0.0" />
  </feature>
  
  <!-- Cordova API -->
  <access subdomains="true" uri="file:///store/home" />
  <access subdomains="true" uri="file:///SDCard" />

  <!-- Expose access to all URIs, including the file and http protocols -->
  <access uri="*" subdomains="true" />

  <icon rim:hover="false" src="res/icon/blackberry/ic_launcher.png" />
  <icon rim:hover="true" src="res/icon/blackberry/ic_launcher.png" />

  <rim:loadingScreen backgroundColor="#CC0000"
                     foregroundImage="res/screen/blackberry/screen-225.png"
		     onFirstLaunch="true">
    <rim:transitionEffect type="fadeOut" />
  </rim:loadingScreen>

  <content src="index.html" />

  <rim:permissions>
    <rim:permit>use_camera</rim:permit>
    <rim:permit>read_device_identifying_information</rim:permit>
    <rim:permit>access_shared</rim:permit>
    <rim:permit>read_geolocation</rim:permit>
    <rim:permit>record_audio</rim:permit> 
    <rim:permit>access_pimdomain_contacts</rim:permit> 
  </rim:permissions>

</widget>

 

Please use plain text.
BlackBerry Development Advisor
bryanhiggins
Posts: 202
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

Hi,

 

Could you try webkitResolveLocalFileSystemURL? resolveLocalFileSystemURI is a cordova API.

 

You will also need need to set blackberry.io.sandbox = true

 

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Please use plain text.
Contributor
kdart89
Posts: 10
Registered: ‎03-26-2013
My Device: BlackBerry Z10

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

Hi Bryan,

 

Thanks - that's certainly got me further! As the note says in the documentation (which I've now found for blackberry.io) - switching off sandboxing (you said set blackberry.io to true, whereas I set it to false and it worked), you have to reference every file/directory by its full path.

 

Is that true for every file/directory? Is there a reason why blackberry.io.file and blackberry.io.dir is undefined?

 

Thanks again,

Kelvin

Please use plain text.
BlackBerry Development Advisor
bryanhiggins
Posts: 202
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

Hi Kelvin,

 

That's right - my mistake. With sandbox = false, you have access to the entire file system and must provide the full path. Otherwise the path is relative to sandbox root.

 

blackberry.io.file and blackberry.io.dir are not supported on BB10 since that functionality is covered by the HTML5 spec. Cordova includes those in config.xml in case you want to target BBOS or TabletOS.

 

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Please use plain text.
Developer
jeff_sawatzky
Posts: 29
Registered: ‎04-01-2013
My Device: Z10

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

[ Edited ]

I've tried both

blackberry.io.sandbox = true;

and

blackberry.io.sandbox = false;

but according to this, it is supposed to be false. Neither of these helped me out.

 

I also tried using webkitResolveLocalFileSystemURL (along with the changes above), but now I get a FileError.ENCODING_ERR. Also, I need to build this app for multiple platforms (iOS, Android, BB10, etc) so I would prefer to use the cordova API (and the iOS and Android apps currently work with the current cordova api), and not have to riddle my code with BB10 specific code.

 

A poster on StackExchange also suggested to add <access subdomains="true" uri="file:///accounts" /> to my config, which I did, but with no success.

Please use plain text.
BlackBerry Development Advisor
bryanhiggins
Posts: 202
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

Hi,

 

Thanks for posting the detailed HTML page. I compiled it in cordova and could reproduce the issue.

 

It boils down to the fact that webkitResolveLocalFileURL can only access "local" files. Those are files within the application sandbox. I was incorrect that setting blackberry.io.sandbox = false would affect this.

 

Do you already have this same code running on iOS and Android? I'm curious if the cordova resolveLocalFileURI implementation supports this. We would look at adding that capability for BB10.

 

In the meantime, you will need to do the following:

1) blackberry.io.sandbox = false

2) window.requestFileSystem

3) root.getFile

 

 

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Please use plain text.
Developer
jeff_sawatzky
Posts: 29
Registered: ‎04-01-2013
My Device: Z10

Re: window.resolveLocalFileSystemURI returning FileError.NOT_FOUND_ERR

Well, window.resolveLocalFileSystemURI works on Android for certain.

 

To give some background context, here is what happened:

 

We wrote a cordova app for iOS first, taking the imageURL from the navigator.camera.getPicture success callback and passing it directly to the FileTransfer.upload method. Everything worked fine.

 

We then tried to get the app running on Android, which had it's own issues. For instance the imageURL that we got back from the navigator.camera.getPicture success callback looked something like content:///path_to_file which caused errors in the FileTransfer.upload method. We worked around this by taking the imageURI, passing it to window.resolveLocalFileSystemURI, and then using the FileEntry.toURL method to get a proper file:///path_to_file which we could then successfully pass to the FileTransfer.upload method. So it works for certain on Android. We haven't tested this new updated code on iOS since the iOS app is currently working with the old code, and if it aint broke don't fix it. :smileyhappy:

 

Now we are trying to get it working on BB10, and I have tried passing the imageURI directly to the FileTransfer.upload method (like we do in iOS) as well as passing it through window.resolveLocalFileSystemURI. In the first case the FileTransfer errors out with a FileTransferError.FILE_NOT_FOUND_ERR, and in the second case the window.resolveLocalFileSystemURI errors out with a FileError.NOT_FOUND_ERR.

 

So, I'm really hoping I can get some common way of taking a photo, getting the imageURI, and then uploading it using a FileTransfer. I know this is what cordova is supposed to do, but it seems like I still have to make weird work arounds for everything.

Please use plain text.