4

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?

Chris Forrence
  • 10,042
  • 11
  • 48
  • 64
tpow
  • 7,600
  • 11
  • 59
  • 84

1 Answers1

17

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.

fractious
  • 1,642
  • 16
  • 30
Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
  • But how to display the image then? I have been trying with fullPath, nativeUrl etc but nothing working for me :( – atif Jan 25 '15 at 18:21