Cordova camera plugin always returns the same image when choosing from a gallery with a file URI

After updating to the latest version of cordova camera lib 0.3.4, I can get a real uri image after selecting the image from the gallery, the pic.jpg file returned, however, if I select another one, it will return the same image with the same pic name. jpg, so I'm stuck with the same image :(

the image path looks like a file: ///storage/emulated/0/android/data/app/cache/.pic.jpg

Any idea?

https://github.com/apache/cordova-plugin-camera/blob/master/src/android/CameraLauncher.java

$scope.getPhoto = function() { // Retrieve image file location from specified source navigator.camera.getPicture($scope.processImageUri, $scope.onFail, { quality: 88, correctOrientation: true, encodingType: Camera.EncodingType.JPEG, destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY, allowEdit: true }); 
+5
source share
2 answers

write this code after your function and replace your "destinationType:" with mine

  function capturePhoto() { // Take picture using device camera and retrieve image as base64-encoded string navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, destinationType: destinationType.DATA_URL }); } 
+1
source

I also ran into this issue on the iOS platform (iOS 10.2). I did not want to use the decision made to switch to DATA_URI because I use the same code between iOS and Android and would like to support only FILE_URI.

I started debugging and found that this was due to a call to the cleanup function after receiving the image. Since the file is deleted from the temporary storage in the cleaning file, the plugin provides the same file name for the next image. It is logical that everything should be fine, but here, when the web view is evil, it selects the old image from its cache, as the URL is the same as the previous one.

I came with a little fix. Tested this, and in my case it worked fine.

I have a forked repo camera plugin and a modified method generating a temporary file name.

I skipped the tutorial for the parent repository and my commit is not in the right format, so I think my transfer request will be rejected. (I will update and recreate it as I receive some time).

But for now, if you do not plan to remove / add the platform (which can clone from the main repo, losing this change), you can try this solution.

+1
source

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


All Articles