@fengzos/file-transfer v0.1.1
@fengzos/file-transfer
file-transfer
Install
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 for help.
Android
If using Directory.Documents
or
Directory.ExternalStorage
, this API requires the following permissions be added to your AndroidManifest.xml
:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Read about Setting Permissions in the Android Guide for more information on setting Android permissions.
Note that Directory.Documents
and
Directory.ExternalStorage
are only available on Android 9 or older.
API
checkPermissions()
requestPermissions()
uploadFile(...)
downloadFile(...)
addListener('progress', ...)
removeAllListeners()
- Interfaces
- Type Aliases
- Enums
checkPermissions()
checkPermissions() => Promise<PermissionStatus>
Check read/write permissions.
Required on Android, only when using Directory.Documents
or
Directory.ExternalStorage
.
Returns: Promise<PermissionStatus>
Since: 1.0.0
requestPermissions()
requestPermissions() => Promise<PermissionStatus>
Request read/write permissions.
Required on Android, only when using Directory.Documents
or
Directory.ExternalStorage
.
Returns: Promise<PermissionStatus>
Since: 1.0.0
uploadFile(...)
uploadFile(options: UploadFileOptions) => Promise<UploadFileResult>
Uploads the specified file to the server URL provided using an HTTP multipart request.
Param | Type | Description |
---|---|---|
options | UploadFileOptions | UploadFileOptions |
Returns: Promise<HttpResponse>
downloadFile(...)
downloadFile(options: DownloadFileOptions) => Promise<DownloadFileResult>
Downloads a file form a given URL and saves it to the specified directory.
Param | Type | Description |
---|---|---|
options | DownloadFileOptions | DownloadFileOptions |
Returns: Promise<DownloadFileResult>
addListener('progress', ...)
addListener(eventName: 'progress', listenerFunc: ProgressListener) => Promise<PluginListenerHandle> & PluginListenerHandle
Param | Type |
---|---|
eventName | 'progress' |
listenerFunc | ProgressListener |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
removeAllListeners()
removeAllListeners() => Promise<void>
Interfaces
PermissionStatus
Prop | Type |
---|---|
publicStorage | PermissionState |
HttpResponse
Prop | Type |
---|---|
data | any |
status | number |
headers | HttpHeaders |
url | string |
HttpHeaders
UploadFileOptions
Prop | Type | Description |
---|---|---|
url | string | The URL to upload the file to |
name | string | The field name to upload the file with |
blob | Blob | For uploading a file on the web, a JavaScript Blob to upload |
filePath | string | For uploading a file natively, the path to the file on disk to upload |
fileDirectory | Directory | 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 | string |
blob | Blob |
DownloadFileOptions
Prop | Type | Description |
---|---|---|
filePath | string | The path the downloaded file should be moved to |
fileDirectory | Directory | Optionally, the directory to put the file in If this option is used, filePath can be a relative path rather than absolute |
progress | boolean | 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 | () => Promise<void> |
ProgressStatus
Prop | Type |
---|---|
type | ProgressType |
url | string |
bytes | number |
contentLength | number |
Type Aliases
PermissionState
'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'
UploadFileResult
HttpResponse
ProgressListener
(progress: ProgressStatus): void
ProgressType
'DOWNLOAD' | 'UPLOAD'
Enums
Directory
Members | Value | Description | Since |
---|---|---|---|
Documents | "DOCUMENTS" | 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 | "DATA" | 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 | "LIBRARY" | 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 | "CACHE" | 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 | "EXTERNAL" | 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 | "EXTERNAL_STORAGE" | 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 |