tobydeh / nativescript-download-progress

Download large files in Nativescript with progress events
Apache License 2.0
11 stars 16 forks source link

Multiple downloads failed with empty error message #1

Closed karthiksbhat closed 3 years ago

karthiksbhat commented 6 years ago

If the demo apps cannot help and there is no issue for your problem, tell us about it

A loop of downloads causes almost all to fail. Only the first download enters the "then" condition on success.

Which platform(s) does your issue occur on?

Android v6.0.1 Device: Samsung Galaxy C7

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

I have an app that will receive a list of filenames and locations on initial login, and will then attempt to download them, in a loop. So it may need to download anything from 0 files to around 100 files. I have the loop as below, and even introduced a timeout when I thought it was failing due to multiple quick requests. When I ran this code: I got multiple errors like:

JS: An unhandled error occurred in worker: undefined, line: 1 :
JS: Errored with:  Uncaught SyntaxError: Unexpected token } // no idea why this is here
JS: An unhandled error occurred in worker: undefined, line: 1 : // no idea why these are blank
JS: An unhandled error occurred in worker: undefined, line: 1 :
(above line repeats multiple times)
JS: Profiling startup failed to figure out defaults from package.json, error: SyntaxError: Unexpected token O in JSON at position 0 // no idea what this is about
JS: An unhandled error occurred in worker: undefined, line: 1 :
JS: An unhandled error occurred in worker: undefined, line: 1 :
...

Is there any code involved?

// sourceFilePath is of the form: http://X.X.X.X/storage/files/X.abc
// toBeDownloaded[sourceFilePath] is of the form: fs.knownFolders.documents().path + some internal folders
download.addProgressCallback(function(progress) {
                pageData.set("progressBarValue", progress);
            })
            for (var sourceFilePath in toBeDownloaded) {
                timer.setTimeout(() => {
                    download.downloadFile(sourceFilePath, toBeDownloaded[sourceFilePath]).then(function(f) {
                        console.log("Success!");
                        console.log(JSON.stringify(f));
                    })
                    .catch(function(e) {
                        console.log("Errored with: ", e);
                    })
                }, 100);
            }
tobydeh commented 6 years ago

Could you post a link to an example I can run that reproduces the error? I've got a feeling the error's you're seeing aren't related to the download-progress plugin.

yringler commented 5 years ago

I observed a similar problem. ~It seems to me that sometimes the promise is ending in error, even when the download was successful.~ update: Sometimes the download fails. A file is created, but it doesn't contain usable data. See replication here. The file where the error occurs is here.

console.log(`Download error: ${JSON.stringify(err)}`); prints

Download error: {"nativeException":{}}

yringler commented 5 years ago

Confirmed concurrency issue. I workaround by only doing one download at a time, which is bad for the UI. here is the whole file, with the fix. Line 50 is relevant to this issue:

zip(...Array.from(this.files.values())).pipe(
    mergeMap(() => this.loadMedia(lesson))
)

where this.files.values() returns all active downloads. When they finish, I do the new download.

tobydeh commented 5 years ago

Thanks, will take a look.

tobydeh commented 5 years ago

@yringler Can you please check if your issue is resolved in version 1.2.0

trangbtm31 commented 4 years ago

Did anyone fix it? I have the same issue with @karthiksbhat, please help me to check this, I just download file success for the first time, after that, I always fail with an empty error or crash app when I try to download another file to the same directory.