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
{{ message }}
This repository was archived by the owner on Feb 27, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+40-1Lines changed: 40 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,6 +127,38 @@ for (let task of lostTask) {
127
127
128
128
`task.id` is very important for re-attaching the download task with any UI component representing that task, this is why you need to make sure to give sensible IDs that you know what to do with, try to avoid using random IDs.
129
129
130
+
### Using costume headers
131
+
If you need to send costume headers with your download request, you can do in it 2 ways:
132
+
133
+
1) Globally using `RNBackgroundDownloader.setHeaders()`:
134
+
```javascript
135
+
RNBackgroundDownloader.setHeaders({
136
+
Authorization:'Bearer 2we$@$@Ddd223'
137
+
});
138
+
```
139
+
This way, all downloads with have the given headers.
140
+
141
+
2) Per download by passing a headers object in the options of `RNBackgroundDownloader.download()`:
console.log(`Going to download ${expectedBytes} bytes!`);
152
+
}).progress((percent) => {
153
+
console.log(`Downloaded: ${percent *100}%`);
154
+
}).done(() => {
155
+
console.log('Download is done!');
156
+
}).error((error) => {
157
+
console.log('Download canceled due to error: ', error);
158
+
});
159
+
```
160
+
Headers given in the `download` function are **merged** with the ones given in `setHeaders`.
161
+
130
162
## API
131
163
132
164
### RNBackgroundDownloader
@@ -144,6 +176,7 @@ An object containing options properties
144
176
|`id`| String | ✅ | All | A Unique ID to provide for this download. This ID will help to identify the download task when the app re-launches |
145
177
|`url`| String | ✅ | All | URL to file you want to download |
146
178
|`destination`| String | ✅ | All | Where to copy the file to once the download is done |
179
+
| `headers` | Object | | All | Costume headers to add to the download request. These are merged with the headers given in the `setHeaders` function
147
180
|`priority`|[Priority (enum)](#priority-enum---android-only)|| Android | The priority of the download. On Android, downloading is limited to 4 simultaneous instances where further downloads are queued. Priority helps in deciding which download to pick next from the queue. **Default:** Priority.MEDIUM |
148
181
|`network`|[Network (enum)](#network-enum---android-only)|| Android | Give your the ability to limit the download to WIFI only. **Default:** Network.ALL |
149
182
@@ -159,6 +192,12 @@ Checks for downloads that ran in background while you app was terminated. Recomm
159
192
160
193
`DownloadTask[]` - Array of tasks that were running in the background so you can re-attach callbacks to them
161
194
195
+
### `setHeaders(headers)`
196
+
197
+
Sets headers to use in all future downloads.
198
+
199
+
**headers** - Object
200
+
162
201
### DownloadTask
163
202
164
203
A class representing a download task created by `RNBackgroundDownloader.download`
@@ -218,4 +257,4 @@ An absolute path to the app's documents directory. It is recommended that you us
218
257
Developed by [Elad Gil](https://github.com/ptelad) of [Eko](http://www.helloeko.com)
Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "react-native-background-downloader",
3
-
"version": "1.0.2",
3
+
"version": "1.1.0",
4
4
"description": "A library for React-Native to help you download large files on iOS and Android both in the foreground and most importantly in the background.",
0 commit comments