The iOS API is implemented in JavaScript.
The minimum supported API level is 18 and the background file upload is handled by the android-upload-service Open-Source library.
To run the demo open a terminal at the root of the repo and start the server included in demo-server with the command:
npm run start-server
Then, open a second terminal, again at the root of the repo and execute (for Android):
npm run start-demo-android
OR (for iOS)
npm run start-demo-ios
The below attached code snippets demostrate how to use nativescript-background-http, while uploading single or multiple files.
For further help review the (SimpleBackgroundHttp)[https://github.com/NativeScript/nativescript-background-http/tree/master/examples] application.
uploading sigle file to the service
import * as bghttp from "nativescript-background-http";
var session = bghttp.session("image-upload");
.....
var request = {
url: url,
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
"File-Name": name
},
description: description
};
if (should_fail) {
request.headers["Should-Fail"] = true;
}
let task: bghttp.Task;
task = session.uploadFile(file, request);
uploading multiple files while using nativescript-background-http. Make sure all params sent to multipartUpload have string values.
import * as bghttp from "nativescript-background-http";
var session = bghttp.session("image-upload");
.....
var request = {
url: url,
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
"File-Name": name
},
description: description
};
if (should_fail) {
request.headers["Should-Fail"] = true;
}
let task: bghttp.Task;
var params = [
{ name: "test", value: "value" },
{ name: "fileToUpload", filename: file, mimeType: 'image/jpeg' }
];
task = session.multipartUpload(params, request);
We love PRs! Check out the contributing guidelines. If you want to contribute, but you are not sure where to start - look for issues labeled help wanted.
Please, use github issues strictly for reporting bugs or requesting features. For general questions and support, check out the NativeScript community forum or ask our experts in NativeScript community Slack channel.
