Phonegap - save the image, then get its basic 64-encoded data

I use the PhoneGap camera API to take a picture and save it using destinationType.FILE_URI . This part works. Then I can take the provided path and set it as src of the HTML image, and the image will appear.

Later in the code, I want to capture an image, convert it to base64encoded data and transfer it to the server. This is problem.

I get {"code" : 5} (which, according to this , means its invalid URI) in my failover callback when using:

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

I do not understand why I can install img.src , but phoneGap cannot use the same URI to find the file?

+4
source share
1 answer

This is because Android has a URI handler for the content:// protocol. The file API is not working. However, you can convert the content:// type URI to FileEntry . Using:

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

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

+15
source

Source: https://habr.com/ru/post/1397909/


All Articles