plugins
plugins copied to clipboard
[background-http] problems uploading images in the background
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.