Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova camera plugin always return the same image when select from gallery with file URI

After upgrading to the latest cordova camera lib 0.3.4, I am able to get the real image uri after selecting an image from gallery, the returned file call pic.jpg, however if I select another one, it will return the same image with the same name pic.jpg, so I am stuck with the same image :(

the image path looks like 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
        });
like image 254
user1883793 Avatar asked Dec 18 '14 06:12

user1883793


1 Answers

I also faced this issue on iOS platform (iOS 10.2). I didn't want to use accepted solution of moving to DATA_URI because I am using same code between iOS and Android and wanted to keep FILE_URI approach only.

Started debugging and found that it happens because of calling cleanup function after getting picture. Since in cleanup call file is removed from temporary storage, plugin gives same filename to next picture being available. Logically that should be fine, but here web view playing an evil, picks old image from its cache as URL is same as pervious.

I came with a small fix. Tested that and in my case it worked fine.

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

I missed the guideline for parent repository and my commit isn't in required format so I guess my pull request will be declined. (I will update & recreate it as I get some time).

But for now, unless you are planning to remove/add platform (which might clone from master repo loosing the change) you can try this solution.

like image 154
devilzk83 Avatar answered Sep 20 '22 09:09

devilzk83