NativeScript download images and store them locally

0

Hi, I have a problem with nativescript, I have an array of objects in the get a service, each objteto has the name of the linked image and I go through it to get that name, I set it as a concatenation to a url and thus get the image.

The problem seems to be that it does not support download queuing, in different devices it can get downloads of 80 to 240 images and these weighing less than 200kb, it is given a settimeout to give it time:

// Iteration method for download

        public downloadImagesProducts(productList: ObservableArray<Product>){
    var l: any;
    var cont = 0;
    var separator = 0;
    l = productList.length;
    var i = 0;
    console.log("Largo del array__:"+l);
        productList.map(product => {
            if(product.ImageFile != null){
                this.urlImage = '${SERVER.baseUrl}/Image/${product.ImageFile}';
                console.log(this.urlImage);

                setTimeout(() => {
                    this._productService.getProductImage(this.urlImage,product.ImageFile);
                }, cont);

                i++;
                console.log(i);
            }else{
                //console.log(product.ProductType + "____No tiene imagen___"+contWImage);
                //contWImage++;
            }
            cont += 250;

            if(separator == 80){
                cont += 120000;
                separator = 0;
                console.log("Se lograron 80 deberia esperar");
            }
        });


    console.log("Termino la descarga");


}

// Download method

   public async  getProductImage(url, fileName){

    var filePath = fs.path.join(fs.knownFolders.documents().path, fileName);
        await http.getFile(url, filePath).then(function (r) {
            //// Argument (r) is File!
            console.log(filePath);
        }, function (e) {
            //// Argument (e) is Error!
        });
}

The image download is direct from url, there are more than 1000 images, and the total weight of all of them is approximately 180mb, would recommend better to create a b64 create a json of all the images in b64 and store it in a non-SQL document ?

    
asked by Cap08 27.03.2018 в 18:42
source

0 answers