Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhoneGap - storing an image, then getting its base64encoded data

Tags:

cordova

I am using the PhoneGap Camera API to take a picture and store it using destinationType.FILE_URI. This portion is working. I can subsequently take the path provided and set it as the src of an HTML image, and the image appears.

Later in the code, I want to grab the image, convert it to base64encoded data, and transmit it to the server. This is where the problem is.

I am getting {"code" : 5} (which, according to this, means it's an invalid URI) in my fail callback when using:

fileSystem.root.getFile("content://media/external/images/media/4292", null, gotFileEntry, fail);

I don't understand why I can set an img.src, but phoneGap can't use the same URI to find the file?

like image 620
tpow Avatar asked Dec 03 '22 05:12

tpow


1 Answers

It is because the Android OS has a URI handler for the content:// protocol. The File API does not. However, there is a way for you to convert a content:// type URI into a FileEntry. Use:

window.resolveLocalFileSystemURI("content://media/external/images/media/4292", win, fail);

and the success callback win will be called with a FileEntry for you.

like image 123
Simon MacDonald Avatar answered Mar 04 '23 00:03

Simon MacDonald