plugins icon indicating copy to clipboard operation
plugins copied to clipboard

[background-http] problems uploading images in the background

Open linesharina opened this issue 3 years ago • 0 comments

Hello I'm experiencing problems uploading images in the background when using background-http on iOS.

Here's how I implemented it:

Versions:

"@nativescript/core": "~8.0.0",
"@nativescript/background-http": "^5.0.2",

Implementation:

// filePath is the path to an image
const session = bghttp.session('image-upload')
let file = File.fromPath(filePath)

const params = [
    {
        name: 'files[]',
        filename: filePath,
        mimeType: 'image/jpeg'
    }
]

const task = session.multipartUpload(params, uploadRequestOption)

let data = null
task.on('responded', e => {
    data = e.data
})

task.on('complete', e => {
    if (e.responseCode == 200) {
        responseData = JSON.parse(data)
        // ...
        // ...
        // ...
    }
})

The implementation runs inside a loop.

It worked previously, and I'm not sure when it stopped. I suspect it happened when I migrated from NS 6 to 8.

This works perfectly fine when the phone is open and the app is active, but when I lock the phone or go out of the app it stops running. Any help with this is much appreciated.

linesharina avatar Nov 17 '21 20:11 linesharina