I am developing an application for salespeople in a store. They will need to have the products offline to sell because in some places there is no network, I set up a JSON on my back end that brings all the products. I am writing this JSON with file.write
to query if there is no network to fetch the JSON products I inserted.
But I need to scan this JSON and get the links of the images that are in them, and save the device too, the problem It’s just too many images and result is crash application.
I’m using filetransfer
to download images, how can I download without crash?
My code:
response.products.forEach(item => {
item.midias.forEach(media => {
this.writeImages(media.id_registro, media.imagem_produto);
});
});
...
public writeImages(id: number, fileName: string) {
const fileTransfer: FileTransferObject = this.fileTransfer.create();
const url = `https://cartoesbellaarte.com.br/admin/views/_uploads/${fileName}`;
fileTransfer.download(url, this.file.applicationDirectory + `/images/${id}/${fileName}`).then(async (entry) => {
const toast = await this.toast.create({
message: entry.toURL(),
position: 'bottom',
duration: 3000
});
toast.present();
}, (error) => {
alert('Err on insert: ' + error.error);
});
}