How to get a file object on a successful cordova camera callback?

I am currently using the following approach, in which it provides the details of a file, but not the actual object, which seems to us one of those that we get from javascript / jQuery. Does anyone know how to get a file object from a file URI / native URI from the iOS / android mobile file system using cordova and javascript?

Below is the snippet I'm currently using.

window.resolveLocalFileSystemURL( filepath, function(fileEntry) { fileEntry.file( function(file) { var reader = new FileReader(); reader.onloadend = function() { var imgBlob = new Blob([this.result], {type: "image/jpeg"}); var uploadedFile = imgBlob; uploadedFile.name = file.name; alert("Importing Asset from Camera.. " + uploadedFile.name); alert(uploadedFile.type); alert(uploadedFile.size); importAsset(uploadedFile); }; reader.readAsArrayBuffer(file); }, function(error) { alert("Error in fileEntry.file():" + error) }) }, function(error) { alert("Error in window.resolveLocalFileSystemURL():" + error) } ); 

Note: FileTransfer.upload() will not work in my case.

Above the fragment that I use after you take from the Add image file to form data - Cordova / Angular after passing through the existing Q & A from #SO

+7
javascript android ios cordova phonegap
source share
1 answer

Downloading a Base64 image will work like iOS / Android, as I tried: As for iOS, there is only one way to show that the image uses base64 format. You can use the cordova-camera-plugin to create a base64 image and put on the HTML img tag. I set the flag for receiving data in jpeg, base64 in the camera plugin.

 <img id="cardImg"> 

Save the base64 image in a javascript variable as:

 var imgdata=data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg== 

Then just pass the data to the HTML img tag as:

 cardImg.src=imgdata; 

Done!

-one
source share

All Articles