Reputation: 766
I'm trying to upload an image taken with the device's camera via the FileTransfer.upload method and I'm consistently being given a FILE_NOT_FOUND_ERR
. I'm using Cordova 2.2.0 via PhoneGap Build.
I'm taking a picture and saving the URI for it into localStorage (via Backbone):
navigator.camera.getPicture(
(file_uri) =>
params.file_uri = file_uri
params.is_image = 1
collection.create params
(message) ->
U.Alert "Failed: #{message}"
options
)
Then attempting to upload that image:
file_uri = @get('file_uri')
transferOpts = new FileUploadOptions
transferOpts.fileKey = 'attachment'
transferOpts.fileName = file_uri.substr file_uri.lastIndexOf('/') + 1
transferOpts.chunkedMode = false
transfer = new FileTransfer
transfer.upload(file_uri, @url(), success, error, transferOpts)
With this, the FileTransfer's error
callback is always thrown with the following:
{
code: 1,
http_status: 411,
source: "content://media/external/images/media/8416",
target: "https://mywebapp.com/api/endpoint"
}
Code 1 is PhoneGap's FILE_NOT_FOUND_ERR
response code. But I've verified the file exists on the device. Firstly, I can display the file_uri
as an image on the screen. Secondly, I can retrieve the contents of the image file via the Weinre debugger like so:
var reader = new FileReader();
reader.onloadend = function(e) {
console.log('Read as data URL');
console.log(e.target.result);
};
reader.readAsDataUrl(file_uri);
The logged data:image/jpeg;base64
response is the correct image.
Now, I even tried manually resolving the URI like so, as I've seen in one StackOverflow question:
resolveLocalFileSystemURI file_uri, (fileEntry) => fileEntry.file (fileObj) =>
transferOpts = new FileUploadOptions
transferOpts.fileKey = 'attachment'
transferOpts.fileName = fileObj.name
transferOpts.chunkedMode = false
transfer = new FileTransfer
transfer.upload(fileObj.fullPath, @url(), success, error, transferOpts)
In this case fileObj.fullPath
resolves to: /mnt/sdcard/Android/data/com.COMPANY.APPNAME/cache/1359412873161.jpg
And still no luck. At this point I'm sure it's something stupid I'm missing!
Upvotes: 1
Views: 1385
Reputation: 521
I had similar problem and resolved by using source uri in format "file://"
Upvotes: 1