Filename changes when using allowEdit in a phone stumbling
I am using phonegap to build android app. In this I need to grab an image from the gallery . So I wrote the following code to capture an image
navigator.camera.getPicture(function(imageURI){
window.resolveLocalFileSystemURI(imageURI, function(fileEntry){
fileEntry.file(function(fileObj) {
console.log(fileObj.name);
});
}, fail);
}, fail, { quality: 100, allowEdit : true,
targetWidth: 600,
targetHeight: 600,
destinationType: destinationType.NATIVE_URI,
sourceType: pictureSource.PHOTOLIBRARY
});
It works great and freezes the image.
The problem is that when you insert allowEdit into the camera parameters, the image name changes. If I delete
/*allowEdit : true,
targetWidth: 600,
targetHeight: 600,*/
the name of the image is saved by default.
How to avoid renaming while editing . Someone is helping to solve this problem.
source to share
In phonegap / cordova (version 3.3) when using "allowEdit: true and target height and width" for the camera parameters, the camera plugin has a default name like "resize.jpg" .
Therefore it is always stored as resige.jpg and also only for when displaying an image from the gallery and not when shooting with a camera.
So you can change the default line in cameraLauncher.java (present inside src / org.apache.cordova.camera)
Instead of this
// Create an ExifHelper to save the exif data that is lost during compression
String resizePath = getTempDirectoryPath() + "/resize.jpg";
// Some content: URIs do not map to file paths (e.g. picasa).
String realPath = FileHelper.getRealPath(uri, this.cordova);
Replace this
String realPath = FileHelper.getRealPath(uri, this.cordova);
int postition = realPath.lastIndexOf( '.' );
// your image format like jpg or png
String imageFormat = realPath.substring(postition+1);
// your image name
String imageName = realPath.substring(0,postition);
//now the default name is changed
String resizePath = getTempDirectoryPath() + "/"+imageName+"."+imageFormat;
NOTE * This answer is for android only
source to share