Search code examples
androidcordovafile-uploadandroid-cameracordova-plugins

Cordova Image Upload Duplicate Issue


I'm encountering a very weird phenomenon while uploading files from my Cordova app to the server.

My app allows users to select 2 images (from album / camera) using navigator.camera.getPicture, then retrieves the Camera.DestinationType.FILE_URI, which is later used for uploading via the FileTransfer plugin, sending the file to server in sequence.

Now, the weird problem is, 5 - 10% of the time, the 2 photos uploaded by our Android app users ended up with BOTH being the second photo. That means, after user selected photo 1 and 2, and uploaded both, the server end received the images as both being photo 2.

We've tried asking as much info from users as possible, and we narrowed it down to an issue with Android (works perfectly on iOS). It is most likely not a connection issue, as users had this problem whether on Wifi or 3G, and we're not sure if it's a memory issue, since some newer models encountered this problem as well.

We tried many times but could not replicate this problem with our Android devices (including slower, older ones).

Is there anyone that came across such a weird issue, and is this a problem with the Camera plugin or File Transfer plugin? I'm suspecting it has to do with memory problem, where somehow the app lost or mixed up the file URIs before uploading.

The problem only happens one way - as in BOTH photos became photo 2, but never both becoming photo 1.

Please advise, thanks!

[UPDATE]

I'm noticing a weird phenomenon upon displaying the FILE_URI value passed by getPicture. If I call the getPicture again for the second image, the cache file used by the plugin remains the same. It's always "file:///storage/sdcard0/Android/data/com.myapp/cache/modified.jpg?242432424" (the ending digits are random, but it is ALWAYS "modified.jpg" filename).

This results in the second image overwriting the first one. However, I haven't figured out how most of the time the app successfully uploads 2 separate images instead of same duplicate.

Is this a plugin bug, always using the same filename as the cached image, and could it be related to some phone memory problem? Is there any way to make it use random file names, instead of just appending random parameters to the same file?

My Android is 4.3.1, running Cordova 3.6.

Below is the getPicture code I am using:

        navigator.camera.getPicture(function(imageData) { uploadPhoto(imageData) }, onCameraFail, {
            destinationType: Camera.DestinationType.FILE_URI, sourceType : Camera.PictureSourceType.PHOTOLIBRARY, allowEdit: false, correctOrientation: true, saveToPhotoAlbum: false, targetWidth: 1280, targetHeight: 960
        });

Solution

  • Version 2.1.0 of the camera plugin has already solved that bug. The patch was applied 16 Oct 2015.

    Upgrading the plugin solved the bug in my case at least.