Vydia / react-native-background-upload

Upload files in your React Native app even while it's backgrounded. Supports Android and iOS, including camera roll assets.
MIT License
726 stars 332 forks source link

Event listener 'completed' in background!! not being called #201

Open luigbren opened 4 years ago

luigbren commented 4 years ago

if the application is open, everything works very well, in 'progress' it shows the progress log and in the 'complete' event it also works, when it finishes uploading the file it shows the result, that it already uploaded the file.

Upload.startUpload({
    url: url,
    path: file,
    method: 'POST',
    field: "file",
    type: "multipart",
    parameters: {
        ....
    },
    maxRetries: 2, // set retry count (Android only). Default 2
    headers: {
        'content-type': 'multipart/form-data', // Customize content-type
        'Accept': 'application/json'
    },
    notification: {
        enabled: true,
        notificationChannel: 'UploadMedia',
    },
    useUtf8Charset: true
}).then((uploadId) => {
    Upload.addListener('progress', uploadId, (data) => {
        console.log(`Progress: ${data.progress}%`)
    })
    Upload.addListener('error', uploadId, (data) => {
        //console.log(`Error: ${data.error}%`)
    })
    Upload.addListener('cancelled', uploadId, (data) => {
        //console.log(`Cancelled!`)
    })
    Upload.addListener('completed', uploadId, (data) => { //No Work in background Mode
        count++                       
          if (count == totalLoad) {
           resolve(true)
         }
        console.log('Completed!')
    })
}).catch((err) => {
    console.log('Upload error!', err)
})

but if I send the information and close the application (background mode), if the work continues, the files keep uploading but the 'progress' and 'completed' events don't work

joshua-davis-rose commented 4 years ago

I'm pretty sure that's what this PR is trying to solve, which looks like it's making active progress.