Hi,
Did you get any solution to get the size of a file, I wanted same functionality for my application, if you can provide some code for the solution it would be helpful.
Here is a working service example that list an image folder on the device
and retrieve image file informations such as : name, url, size, date, resolution.
if it can help…
If a cleaner way exists, please let us know
import { Injectable } from '@angular/core';
import { File } from '@ionic-native/file';
declare var window;
declare var cordova;
@Injectable()
export class FileService {
constructor(private file: File) {}
public listAppImages() {
this.file.listDir(cordova.file.dataDirectory, "myImagesFolder").then((files) => {
files.forEach((file, index) => {
console.log("image name : " + file.name);
console.log("image url : " + file.nativeURL);
window.resolveLocalFileSystemURL(file.nativeURL, (fileEntry) => {
fileEntry.getMetadata((metadata) => {
console.log("image size : " + metadata.size);
console.log("image date : " + metadata.modificationTime);
});
fileEntry.file(function(fileObject){
var reader = new FileReader()
reader.onloadend = function(evt) {
var image = new Image()
image.onload = function(evt) {
console.log("image resolution: " + this["width"] + " x " + this["height"]);
image = null
}
image.src = evt.target["result"]
}
reader.readAsDataURL(fileObject)
}, function(){ console.error("There was an error reading or processing this file.") })
}, (error) => { console.error(error); });
});
}).catch((error) => { console.error(error) });
}
}