All,
I'm trying to get the file size (i.e. not the dimensions, but the actual file size in disk) of a photo using PhoneGap/Cordova 2. So far, the only way I can figure it out is through base64 conversion, then basic arithmetic on the bytes of the b64 string. However, I was wondering if there is a more elegant way to get file size. TIA.
clarification: it must work on iOS 5 and Android 2.3.
Yeah, if you have the URL to the image from the Camera.getPicture command you pass it to the window.resolveLocalFileSystemURL command who's success callback is called with a FileEntry object. Then you call the "file" method of FileEntry which calls the success callback with a File object then you can look at the size property of the File object.
Something like....
function takePhoto() {
navigator.camera.getPicture(gotPhoto, onError, { quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.CAMERA });
}
function gotPhoto(imageUri) {
window.resolveLocalFileSystemURI(imageUri, function(fileEntry) {
fileEntry.file(function(fileObj) {
console.log("Size = " + fileObj.size);
});
});
}
that should work but I just wrote the code off the top of my head.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With