jriffel commented on issue #761:
URL: 
https://github.com/apache/cordova-plugin-camera/issues/761#issuecomment-1243943272

   I was able to finally get a solution together that works for our use case.  
As previously mentioned using Data URIs works but then you are hauling around 
huge strings in your app.  This made our app unstable and often terminated (I 
suspect due to memory pressure if someone captured a lot of photos).  We 
require a FileEntry object to upload to the back end server so we do not have 
to hold the media in memory.  However, we used to be able to use a file:// URI 
or similar to display a thumbnail and this is where we were getting the "Not 
allowed to load local resource" error.  The following example code is roughly 
how we solved it where we use the request a file URI, convert it to a FileEntry 
(which we store a reference to for sending), and then get a data URI for the 
thumbnail.  I hope this helps others.
   
   `var cameraOptions = {
        destinationType: Camera.DestinationType.FILE_URI,
          encodingType : Camera.EncodingType.JPEG,
     correctOrientation: true,
             sourceType: Camera.PictureSourceType.CAMERA
   }
   
   navigator.camera.getPicture(
     function(imageURI) {
     resolveLocalFileSystemURL(imageURI, function(fileEntry) {
       // fileEntry is usable for uploading without holding image in memory...
       
       fileEntry.file(function(file) { 
         var reader = new FileReader();
     
         reader.onloadend = function() {
           // this.result contains the Data URI usable as a preview thumbnail
           $('#some-image-id').attr('src', this.result);
         }
     
         reader.readAsDataURL(file);
       }, errHandler);
     }, errHandler);
   }, errHandler, cameraOptions);
   `


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to