cordova-imagePicker: Returning original image using NATIVE_URI, instead of stripped copy

The plugin works great. However, it creates a copy of the image file for further processing. This strips out the original metadata of the image, like the EXIF details. Is it possible to not create a copy, and simply return theCamera.DestinationType.NATIVE_URI instead?

By using the NATIVE_URI, the original file (path) is returned - e.g., assets-library:// on iOS or content:// on Android - and allows processing of the native file, including EXIF data. This has also been fixed in recent Cordova updates, so it’s obvious this hasn’t been used before.

Ideally, an option like for example useOriginal: true, or the quality: 100 to preserve backwards compatability would be a nice solution in my opinion,.

@wymsee: I’m also interested in digging through the code here a bit, but would love some input if this is advisable (and perhaps a bit of a tip where to fix this). Any tips?

About this issue

  • Original URL
  • State: open
  • Created 10 years ago
  • Reactions: 5
  • Comments: 31

Most upvoted comments

This is completely untested code, but maybe it helps you:

window.imagePicker.getPictures(
  function(results) {
    console.log('start!');
        function loopThroughImages(i) {
            if (i < results.length) {
                var origURI = results[i];
                var tmpURI = results[i+1];

                var options = new FileUploadOptions();
                options.fileKey = "file";
                options.fileName = "myTestUpload_"+i+".jpg";
                options.mimeType = "image/jpeg";
                options.chunkedMode = false;

                var params = {};
                params.keywords = 'mobile,upload';
                options.params = params;

                var transfer = new FileTransfer();
                transfer.upload(
                    origURI,
                    encodeURI('PATH/TO/MY/UPLOADSCRIPT'),
                    function(response) {
                        console.log('it worked!');

                            i = i+2;
                            loopThroughImages(i);
                    },
                    function(error) {
                        console.log('ERROR FILEUPLOAD');
                        console.log("An error has occurred: Code = " + error.code);
                        console.log("upload error source " + error.source);
                        console.log("upload error target " + error.target);
                    },
                    options
                );
            }
            else {
                console.log('done!');
            }
        }
        loopThroughImages(0);
  }, function (error) {
    console.log('Error: ' + error);
  }, {
    maximumImagesCount: 50
  }
);