It is necessary to get the file size by the native url.
The value in the message is displayed, but it is not possible to assign it to a variable.
Here is my code:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { ImagePicker } from '@ionic-native/image-picker';
import { File } from '@ionic-native/file';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public images = [];
public sizes = [];
constructor(
public navCtrl: NavController,
private imagePicker: ImagePicker,
private file: File
) { }
openPicker() {
var options = {
quality: 100,
outputType: 0
};
this.imagePicker.getPictures(options).then((results) => {
for(let i=0; i < results.length; i++) {
this.images.push({'url': results[i], 'size': '???'});
this.file.resolveLocalFilesystemUrl(results[i]).then((fileEntry) => {
this.getFileSize(fileEntry);
});
}
setTimeout(() => {
console.log(this.sizes); /* Empty Array !!!!!!!!!!!!!!!!!!! */
}, 1000);
});
}
getFileSize(fileEntry) {
fileEntry.file(function(file) {
alert(file.size); /* Show and work */
this.sizes.push(file.size); /* NOT WORK */
});
}
}
That’s what I really need, but it causes a mistake.
I did not find the documentation of “fileEntry.file” for ionic 2/3
this.imagePicker.getPictures(options).then((results) => {
for(let i=0; i < results.length; i++) {
this.file.resolveLocalFilesystemUrl(results[i]).then((fileEntry) => {
fileEntry.file(function(file) { /* <--------- I did not find the documentation of "fileEntry.file" for ionic 2/3 */
this.images.push({'url': results[i], 'size': file.size});
});
});
}
});
Thankful in advance for the help.