Skip to content Skip to sidebar Skip to footer

Phonegap Getpicture Method Fails When Image File Names With Spaces In Android

I'm using the latest version of the phonegap camera plugin (i.e. 0.2.9) and 3.5 of phonegap Build, testing on Android, below is my code for getting images: navigator.camera.getPict

Solution 1:

Use JavaScript encodeURI() Function to encode the path.

This will give you the file path in a format accepted by the standard specification. Still '(' and ')', which appears commonly on file names, are not handled by the function.

However, tailing the encodeURI function with 2 JavaScript String replace() Method to replace them with their RAW URL encoding equivalents should solve the issue.

var success = function(path) {
  var urlEncodedPath = encodeURI(path)
    .replace('(', '%28')
    .replace(')', '%29');
  document.getElementById("demo").innerHTML = urlEncodedPath;
  // do something
};

// Actual success callback from cordova camera// navigator.camera.getPicture(success, fail, options);// An Example for demonstating in browsersuccess('file:///storage/emulated/0/Android/data/com.your.app/cache/hd wallpaper nature(1).jpg');
<pid="demo"style="word-wrap: break-word;"></p>

Solution 2:

My solution is to update to the latest version (5.1.1).

Post a Comment for "Phonegap Getpicture Method Fails When Image File Names With Spaces In Android"