Cordova / PhoneGap照片文件大小 [英] Cordova/PhoneGap Photo File Size
问题描述
全部,
我尝试使用PhoneGap / Cordova获取照片的文件大小(即不是尺寸,而是磁盘中的实际文件大小)到目前为止,我唯一能找到的方法是通过base64转换,然后对b64字符串的字节进行基本算术。然而,我想知道是否有一个更优雅的方式来获取文件大小。 TIA。
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.
澄清:它必须适用于iOS 5和Android 2.3。
clarification: it must work on iOS 5 and Android 2.3.
推荐答案
是的,如果你有来自Camera.getPicture命令的图像的URL,你将它传递给window.resolveLocalFileSystemURL命令谁成功回调用FileEntry对象调用。然后你调用FileEntry的file方法,使用File对象调用成功回调,然后你可以看看File对象的size属性。
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.
有点像。 ...
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.
这篇关于Cordova / PhoneGap照片文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!