You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/background-http/README.md
+37-38
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
# Nativescript background-http
1
+
# @nativescript/background-http
2
2
3
-
```javascript
3
+
```cli
4
4
ns plugin add @nativescript/background-http
5
5
```
6
6
@@ -12,24 +12,23 @@ The below attached code snippets demonstrate how to use `@nativescript/backgroun
12
12
13
13
Sample code for configuring the upload session. Each session must have a unique `id`, but it can have multiple tasks running simultaneously. The `id` is passed as a parameter when creating the session (the `image-upload` string in the code bellow):
14
14
15
-
```JavaScript
16
-
15
+
```javascript
17
16
// file path and url
18
-
var file ="/some/local/file/path/and/file/name.jpg";
19
-
var url ="https://some.remote.service.com/path";
20
-
var name =file.substr(file.lastIndexOf("/") +1);
17
+
var file ='/some/local/file/path/and/file/name.jpg';
18
+
var url ='https://some.remote.service.com/path';
19
+
var name =file.substr(file.lastIndexOf('/') +1);
21
20
22
21
// upload configuration
23
-
var bghttp =require("@nativescript/background-http");
24
-
var session =bghttp.session("image-upload");
22
+
var bghttp =require('@nativescript/background-http');
23
+
var session =bghttp.session('image-upload');
25
24
var request = {
26
-
url: url,
27
-
method:"POST",
28
-
headers: {
29
-
"Content-Type":"application/octet-stream"
30
-
},
31
-
description:"Uploading "+ name
32
-
};
25
+
url: url,
26
+
method:'POST',
27
+
headers: {
28
+
'Content-Type':'application/octet-stream',
29
+
},
30
+
description:'Uploading '+ name,
31
+
};
33
32
```
34
33
35
34
For a single file upload, use the following code:
@@ -57,30 +56,30 @@ In order to have a successful upload, the following must be taken into account:
57
56
58
57
The request object parameter has the following properties:
59
58
60
-
Name | Type | Description
61
-
--- | --- | ---
62
-
url | `string` | The request url (e.g.`https://some.remote.service.com/path`).
63
-
method | `string` | The request method (e.g. `POST`).
64
-
headers | `object` | Used to specify additional headers.
65
-
description | `string` | Used to help identify the upload task locally - not sent to the remote server.
66
-
utf8 | `boolean` | (Android only/multipart only) If true, sets the charset for the multipart request to UTF-8. Default is false.
67
-
androidDisplayNotificationProgress | `boolean` | (Android only) Used to set if progress notifications should be displayed or not. Please note that since API26, Android requires developers to use notifications when running background tasks. https://developer.android.com/about/versions/oreo/background
68
-
androidNotificationTitle | `string` | (Android only) Used to set the title shown in the Android notifications center.
69
-
androidAutoDeleteAfterUpload | `boolean` | (Android only) Used to set if files should be deleted automatically after upload.
70
-
androidMaxRetries | `number` | (Android only) Used to set the maximum retry count. The default retry count is 0. https://github.com/gotev/android-upload-service/wiki/Recipes#backoff
71
-
androidAutoClearNotification | `boolean` | (Android only) Used to set if notifications should be cleared automatically upon upload completion. Default is false. Please note that setting this to true will also disable the ringtones.
72
-
androidRingToneEnabled | `boolean` | (Android only) Used to set if a ringtone should be played upon upload completion. Default is true. Please note that this flag has no effect when `androidAutoClearNotification` is set to true.
73
-
androidNotificationChannelID | `string` | (Android only) Used to set the channel ID for the notifications.
|url |`string`| The request url (e.g.`https://some.remote.service.com/path`).|
62
+
|method |`string`| The request method (e.g. `POST`).|
63
+
|headers |`object`| Used to specify additional headers.|
64
+
|description |`string`| Used to help identify the upload task locally - not sent to the remote server.|
65
+
|utf8 |`boolean`| (Android only/multipart only) If true, sets the charset for the multipart request to UTF-8. Default is false.|
66
+
|androidDisplayNotificationProgress |`boolean`| (Android only) Used to set if progress notifications should be displayed or not. Please note that since API26, Android requires developers to use notifications when running background tasks. https://developer.android.com/about/versions/oreo/background|
67
+
|androidNotificationTitle |`string`| (Android only) Used to set the title shown in the Android notifications center.|
68
+
|androidAutoDeleteAfterUpload |`boolean`| (Android only) Used to set if files should be deleted automatically after upload.|
69
+
|androidMaxRetries |`number`| (Android only) Used to set the maximum retry count. The default retry count is 0. https://github.com/gotev/android-upload-service/wiki/Recipes#backoff|
70
+
|androidAutoClearNotification |`boolean`| (Android only) Used to set if notifications should be cleared automatically upon upload completion. Default is false. Please note that setting this to true will also disable the ringtones.|
71
+
|androidRingToneEnabled |`boolean`| (Android only) Used to set if a ringtone should be played upon upload completion. Default is true. Please note that this flag has no effect when `androidAutoClearNotification` is set to true.|
72
+
|androidNotificationChannelID |`string`| (Android only) Used to set the channel ID for the notifications.|
74
73
75
74
The task object has the following properties and methods, that can be used to get information about the upload:
76
75
77
-
Name | Type | Description
78
-
--- | --- | ---
79
-
upload | `number` | Bytes uploaded.
80
-
totalUpload | `number` | Total number of bytes to upload.
81
-
status | `string` | One of the following: `error`, `uploading`, `complete`, `pending`, `cancelled`.
82
-
description | `string` | The description set in the request used to create the upload task.
83
-
cancel()| `void` | Call this method to cancel an upload in progress.
|totalUpload |`number`| Total number of bytes to upload.|
80
+
|status |`string`| One of the following: `error`, `uploading`, `complete`, `pending`, `cancelled`.|
81
+
|description |`string`| The description set in the request used to create the upload task.|
82
+
|cancel()|`void`| Call this method to cancel an upload in progress.|
84
83
85
84
### Handling upload events
86
85
@@ -152,7 +151,7 @@ node server 8080
152
151
153
152
The above commands will start a server listening on port 8080. Remember to update the URL in your app to match the address/port where the server is running.
154
153
155
-
>Note: If you are using the iOS simulator then `http://localhost:8080` should be used to upload to the demo server. If you are using an Android emulator, `http://10.0.2.2:8080` should be used instead.
154
+
>Note: If you are using the iOS simulator then `http://localhost:8080` should be used to upload to the demo server. If you are using an Android emulator, `http://10.0.2.2:8080` should be used instead.
0 commit comments