# cordova-plugin-background-filetransfer

> *Cordova plugin background file transfer* ========================================================= This plugin givess you the android DownloadManager methods for cordova. At the moment we only supports android projects, but we are planning implement the

Latest version **0.0.3** (published 2021-08-26) · Apache 2.0 license · 0 weekly downloads

## Install

```sh
npm install cordova-plugin-background-filetransfer
pnpm add cordova-plugin-background-filetransfer
yarn add cordova-plugin-background-filetransfer
bun add cordova-plugin-background-filetransfer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2021-08-26 |
| First published | 2021-07-26 |
| Weekly downloads | 0 |
| License | Apache 2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 21.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Santiago Cardenas |
| Maintainers | snt1017 |
| Keywords | ecosystem:cordova, cordova-android, download manager, android, files, downaload native, Android DownloadManager, Background download, Android native download |

## Links

- npm: https://www.npmjs.com/package/cordova-plugin-background-filetransfer
- Repository: https://github.com/snt1017/cordova-plugin-background-filetransfer
- Homepage: https://github.com/snt1017/cordova-plugin-background-filetransfer/
- Issues: https://github.com/snt1017/cordova-plugin-background-filetransfer/issues
- npm.io page: https://npm.io/package/cordova-plugin-background-filetransfer

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 0.0.3 (latest) — 2021-08-26
- 0.0.2 — 2021-08-21
- 0.0.1 — 2021-07-26

## README

*Cordova plugin background file transfer*
=========================================================
This plugin givess you the android DownloadManager methods for cordova. At the moment we only supports android projects, but we are planning implement the features for iOS. In the future, the possibility of uploading files will be added too.



# Instalation <a name="instalation"></a>
```bash
cordova plugin add cordova-plugin-background-filetransfer
```

# API Reference <a name="reference"></a>
* [Download service](#downloadService)
    * [.setDownloadPreferences(options)](#downloadService.setDownloadPreferences) : <code>Promise</code>
    * [.getDownloadPreferences()](#downloadService.getDownloadPreferences) : <code>Promise</code>
    * [DownloadPreferences](#downloadService.DownloadPreferences) : <code>Object</code>
    * [.addUrlToDownload(options)](#downloadService.addUrlToDownload) : <code>Promise</code>
    * [DownloadOptions](#downloadService.DownloadOptions) : <code>Object</code>
    * [.getFilesByStatus()](#downloadService.getFilesByStatus) : <code>Promise</code>
    * [.getFileInfoById()](#downloadService.getFileInfoById) : <code>Promise</code>



## Download service <a name="downloadService"></a>


### .setDownloadPreferences(options) <a name="downloadService.setDownloadPreferences"></a>

Set default values of the plugin.

| Param | Type | Description |
| --- | --- | --- |
| options | <code>[DownloadPreferences](#downloadService.DownloadPreferences)</code> | Default download preferences |


```javascript
cordova.plugins.BackgroundFileTransfer.setDownloadPreferences(downloadPreferences).then((result)=> {
  console.log(result);
}, (err) => {
  console.error(err);
});
```

### .getDownloadPreferences() <a name="downloadService.getDownloadPreferences"></a>

Get default values of the plugin.

```javascript
cordova.plugins.BackgroundFileTransfer.getDownloadPreferences().then((result)=> {
  console.log(result);
}, (err) => {
  console.error(err);
});
```

### DownloadPreferences <a name="downloadService.DownloadPreferences"></a>

Optional parameters to customize download settings.


| Name | Type | Default | Description |
| --- | --- | --- | --- |
| allowNetworkMobile | <code>Boolean</code> | <code>true</code> | Allow download files from mobile network |
| allowNetworkWifi | <code>Boolean</code> | <code>true</code> | Allow download files from wifi network |
| allowedOverMetered | <code>Boolean</code> | <code>true</code> | Allow download files in metered networks |
| allowedOverRoaming | <code>Boolean</code> | <code>true</code> | Allow download files when roaming is activated |
| defaultTitle | <code>String</code> | <code>"DownloadService"</code> | This is notification title |

### addUrlToDownload(downloadOptions) <a name="downloadService.addUrlToDownload"></a>

Add new url to enqueue download files. It returns the id of the file download.

```javascript
cordova.plugins.BackgroundFileTransfer.addUrlToDownload(downloadOptions).then((result)=> {
  console.log(result);
}, (err) => {
  console.error(err);
});
```

### DownloadOptions <a name="downloadService.DownloadOptions"></a>

The options that are required for add new download to enqueue.

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| url | <code>String</code> | Required | Allow download files from mobile network. |
| filename | <code>String</code> | Required | Filename, the name under which the file will be saved in the folder.  |
| relativePath | <code>String</code> | Optional value | Name of the folder in which the file is to be saved the file to be saved the file to be saved. |
| headers | <code>{"KEY": "VALUE"}</code> | Optional value | Headers for download if it are required. |
| description | <code>String</code> | filename | The description of the download, this value is displayed in the notification. |


### getFilesByStatus(downloadFileStatus) <a name="downloadService.getFilesByStatus"></a>

Returns the list of files filtered by status. Posible values:

| Status | Value |
| --- | --- |
| PENDING | 1 |
| RUNNING | 2 |
| PAUSED | 4 |
| SUCCESSFUL | 8 |
| FAILED | 16 |


```javascript
cordova.plugins.BackgroundFileTransfer.getFilesByStatus(downloadFileStatus).then((result)=> {
  console.log(result);
}, (err) => {
  console.error(err);
});
```


### getFileInfoById(fileId) <a name="downloadService.getFileInfoById"></a>

Returns the file list filtered by downloaded id.

```javascript
cordova.plugins.BackgroundFileTransfer.getFileInfoById(fileId).then((result)=> {
  console.log(result);
}, (err) => {
  console.error(err);
});
```
## Notes
Be sure that your AndroidManifest.xml contains this permission 
``` xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
```

## Help liks:

[Android Downloader manager](https://developer.android.com/reference/android/app/DownloadManager)

---
_Source: https://npm.io/package/cordova-plugin-background-filetransfer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
