npm package: @fengzos/file-transfer
Description: file-transfer
Author: Bevist
Latest version: 0.1.1

# @fengzos/file-transfer

file-transfer

## Install

```bash
npm install @fengzos/file-transfer
npx cap sync
```

## iOS

To have files appear in the Files app, you must set the following keys to `YES` in `Info.plist`:

- `UIFileSharingEnabled` (`Application supports iTunes file sharing`)
- `LSSupportsOpeningDocumentsInPlace` (`Supports opening documents in place`)

Read about [Configuring iOS](https://capacitorjs.com/docs/ios/configuration) for help.

## Android

If using <a href="#directory">`Directory.Documents`</a> or
`Directory.ExternalStorage`, this API requires the following permissions be added to your `AndroidManifest.xml`:

```xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
```

Read about [Setting Permissions](https://capacitorjs.com/docs/android/configuration#setting-permissions) in the [Android Guide](https://capacitorjs.com/docs/android) for more information on setting Android permissions.

Note that <a href="#directory">`Directory.Documents`</a> and
`Directory.ExternalStorage` are only available on Android 9 or older.


## API

<docgen-index>

* [`checkPermissions()`](#checkpermissions)
* [`requestPermissions()`](#requestpermissions)
* [`uploadFile(...)`](#uploadfile)
* [`downloadFile(...)`](#downloadfile)
* [`addListener('progress', ...)`](#addlistenerprogress)
* [`removeAllListeners()`](#removealllisteners)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)
* [Enums](#enums)

</docgen-index>

<docgen-api>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

### checkPermissions()

```typescript
checkPermissions() => Promise<PermissionStatus>
```

Check read/write permissions.
Required on Android, only when using <a href="#directory">`Directory.Documents`</a> or
`Directory.ExternalStorage`.

**Returns:** <code>Promise&lt;<a href="#permissionstatus">PermissionStatus</a>&gt;</code>

**Since:** 1.0.0

--------------------


### requestPermissions()

```typescript
requestPermissions() => Promise<PermissionStatus>
```

Request read/write permissions.
Required on Android, only when using <a href="#directory">`Directory.Documents`</a> or
`Directory.ExternalStorage`.

**Returns:** <code>Promise&lt;<a href="#permissionstatus">PermissionStatus</a>&gt;</code>

**Since:** 1.0.0

--------------------


### uploadFile(...)

```typescript
uploadFile(options: UploadFileOptions) => Promise<UploadFileResult>
```

Uploads the specified file to the server URL provided using an HTTP multipart request.

| Param         | Type                                                            | Description                                        |
| ------------- | --------------------------------------------------------------- | -------------------------------------------------- |
| **`options`** | <code><a href="#uploadfileoptions">UploadFileOptions</a></code> | <a href="#uploadfileoptions">UploadFileOptions</a> |

**Returns:** <code>Promise&lt;<a href="#httpresponse">HttpResponse</a>&gt;</code>

--------------------


### downloadFile(...)

```typescript
downloadFile(options: DownloadFileOptions) => Promise<DownloadFileResult>
```

Downloads a file form a given URL and saves it to the specified directory.

| Param         | Type                                                                | Description                                            |
| ------------- | ------------------------------------------------------------------- | ------------------------------------------------------ |
| **`options`** | <code><a href="#downloadfileoptions">DownloadFileOptions</a></code> | <a href="#downloadfileoptions">DownloadFileOptions</a> |

**Returns:** <code>Promise&lt;<a href="#downloadfileresult">DownloadFileResult</a>&gt;</code>

--------------------


### addListener('progress', ...)

```typescript
addListener(eventName: 'progress', listenerFunc: ProgressListener) => Promise<PluginListenerHandle> & PluginListenerHandle
```

| Param              | Type                                                          |
| ------------------ | ------------------------------------------------------------- |
| **`eventName`**    | <code>'progress'</code>                                       |
| **`listenerFunc`** | <code><a href="#progresslistener">ProgressListener</a></code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>

--------------------


### removeAllListeners()

```typescript
removeAllListeners() => Promise<void>
```

--------------------


### Interfaces


#### PermissionStatus

| Prop                | Type                                                        |
| ------------------- | ----------------------------------------------------------- |
| **`publicStorage`** | <code><a href="#permissionstate">PermissionState</a></code> |


#### HttpResponse

| Prop          | Type                                                |
| ------------- | --------------------------------------------------- |
| **`data`**    | <code>any</code>                                    |
| **`status`**  | <code>number</code>                                 |
| **`headers`** | <code><a href="#httpheaders">HttpHeaders</a></code> |
| **`url`**     | <code>string</code>                                 |


#### HttpHeaders


#### UploadFileOptions

| Prop                | Type                                            | Description                                                                                                                     |
| ------------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| **`url`**           | <code>string</code>                             | The URL to upload the file to                                                                                                   |
| **`name`**          | <code>string</code>                             | The field name to upload the file with                                                                                          |
| **`blob`**          | <code>Blob</code>                               | For uploading a file on the web, a JavaScript Blob to upload                                                                    |
| **`filePath`**      | <code>string</code>                             | For uploading a file natively, the path to the file on disk to upload                                                           |
| **`fileDirectory`** | <code><a href="#directory">Directory</a></code> | Optionally, the directory to look for the file in. If this option is used, filePath can be a relative path rather than absolute |


#### DownloadFileResult

| Prop       | Type                |
| ---------- | ------------------- |
| **`path`** | <code>string</code> |
| **`blob`** | <code>Blob</code>   |


#### DownloadFileOptions

| Prop                | Type                                            | Description                                                                                                                                                           |
| ------------------- | ----------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`filePath`**      | <code>string</code>                             | The path the downloaded file should be moved to                                                                                                                       |
| **`fileDirectory`** | <code><a href="#directory">Directory</a></code> | Optionally, the directory to put the file in If this option is used, filePath can be a relative path rather than absolute                                             |
| **`progress`**      | <code>boolean</code>                            | Optionally, the switch that enables notifying listeners about downloaded progress If this option is used, progress event should be dispatched on every chunk received |


#### PluginListenerHandle

| Prop         | Type                                      |
| ------------ | ----------------------------------------- |
| **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |


#### ProgressStatus

| Prop                | Type                                                  |
| ------------------- | ----------------------------------------------------- |
| **`type`**          | <code><a href="#progresstype">ProgressType</a></code> |
| **`url`**           | <code>string</code>                                   |
| **`bytes`**         | <code>number</code>                                   |
| **`contentLength`** | <code>number</code>                                   |


### Type Aliases


#### PermissionState

<code>'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'</code>


#### UploadFileResult

<code><a href="#httpresponse">HttpResponse</a></code>


#### ProgressListener

<code>(progress: <a href="#progressstatus">ProgressStatus</a>): void</code>


#### ProgressType

<code>'DOWNLOAD' | 'UPLOAD'</code>


### Enums


#### Directory

| Members               | Value                           | Description                                                                                                                                                                                                                                                                                                                                                                                                                                       | Since |
| --------------------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`Documents`**       | <code>"DOCUMENTS"</code>        | The Documents directory On iOS it's the app's documents directory. Use this directory to store user-generated content. On Android it's the Public Documents folder, so it's accessible from other apps. It's not accesible on Android 10 unless the app enables legacy External Storage by adding `android:requestLegacyExternalStorage="true"` in the `application` tag in the `AndroidManifest.xml`. It's not accesible on Android 11 or newer. | 1.0.0 |
| **`Data`**            | <code>"DATA"</code>             | The Data directory On iOS it will use the Documents directory. On Android it's the directory holding application files. Files will be deleted when the application is uninstalled.                                                                                                                                                                                                                                                                | 1.0.0 |
| **`Library`**         | <code>"LIBRARY"</code>          | The Library directory On iOS it will use the Library directory. On Android it's the directory holding application files. Files will be deleted when the application is uninstalled.                                                                                                                                                                                                                                                               | 1.1.0 |
| **`Cache`**           | <code>"CACHE"</code>            | The Cache directory Can be deleted in cases of low memory, so use this directory to write app-specific files that your app can re-create easily.                                                                                                                                                                                                                                                                                                  | 1.0.0 |
| **`External`**        | <code>"EXTERNAL"</code>         | The external directory On iOS it will use the Documents directory On Android it's the directory on the primary shared/external storage device where the application can place persistent files it owns. These files are internal to the applications, and not typically visible to the user as media. Files will be deleted when the application is uninstalled.                                                                                  | 1.0.0 |
| **`ExternalStorage`** | <code>"EXTERNAL_STORAGE"</code> | The external storage directory On iOS it will use the Documents directory On Android it's the primary shared/external storage directory. It's not accesible on Android 10 unless the app enables legacy External Storage by adding `android:requestLegacyExternalStorage="true"` in the `application` tag in the `AndroidManifest.xml`. It's not accesible on Android 11 or newer.                                                                | 1.0.0 |

</docgen-api>