Socket
Book a DemoInstallSign in
Socket

capacitor-plugin-filedownload

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

capacitor-plugin-filedownload

a file download plugin for capacitor3.0+

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
24
-27.27%
Maintainers
1
Weekly downloads
 
Created
Source

capacitor-plugin-filedownload

a file download plugin for capacitor3.0+

since v2.0.0 supported Capacitor5

since version 1.0.6 , the uri option was changed to url

Install

npm install capacitor-plugin-filedownload
npx cap sync

eg:

import { FileDownload } from "capacitor-plugin-filedownload";

const download = async () => {
  FileDownload.download({
    url: "http://www.xxxxx.com/file/rvh.apk",
    fileName: "release.apk",
    // headers for http request with POST method
    headers: {},
    // parameter for http request with POST method
    body: {},
    // only works on Android, deprecated since 1.0.6
    downloadTitle: 'downloading',
    // only works on Android, deprecated since 1.0.6
    downloadDescription: 'file is downloading',
  }).then((res) => {
    console.log(res.path);
  }).catch(err => {
    console.log(err);
  })
}


// cancel download
const cancelDownload = async () => {
  await FileDownload.cancel();
}


// get download status
const getDownloadStatus = () => {
  const {isCanceled} = await FileDownload.isCanceled();
  console.log(isCanceled);
}


// event listener for downloadProgress
const onDownloadProgress = async () => {
  const eventListener = await FileDownload.addListener('downloadProgress', data =>{
    console.log(data.progress);
  })

  // remove eventListener
  eventListener.remove();
}

...

if you wish to open the file, you can install this plugin: https://github.com/capacitor-community/file-opener

API

download(...)

download(options: FileDownloadOptions) => Promise<FileDownloadResponse>
ParamType
optionsFileDownloadOptions

Returns: Promise<FileDownloadResponse>

cancel()

cancel() => Promise<void>

cancel download

isCanceled()

isCanceled() => Promise<CancelStatus>

get status of download

Returns: Promise<CancelStatus>

checkPermissions()

checkPermissions() => Promise<PermissionStatus>

only for android

Returns: Promise<PermissionStatus>

requestPermissions()

requestPermissions() => Promise<PermissionStatus>

only for android

Returns: Promise<PermissionStatus>

openSetting()

openSetting() => Promise<void>

open app setting, only for android

addListener('downloadProgress', ...)

addListener(eventName: 'downloadProgress', listenerFunc: (progress: FileDownloadProgress) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName'downloadProgress'
listenerFunc(progress: FileDownloadProgress) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle

Interfaces

FileDownloadResponse

PropType
pathstring

FileDownloadOptions

PropTypeDescriptionDefault
urlstring
fileNamestring
destinationDestinationDownload file destinationios default: Document android default: External Storage
headersRecord<string, string>request headers, when headers has value, url must be a http request with POST method
bodyRecord<string, unknown>request body, when body has value, url must be a http request width POST method
downloadTitlestringDownloader Title, Only Android
downloadDescriptionstringDownloader Description, Only Android

CancelStatus

PropType
isCanceledboolean

PermissionStatus

PropTypeDescription
storagePermissionStateprompt: 首次申请,询问。 prompt-with-rationale: 每次都询问。 granted: 已获取权限。 denied:权限已拒绝。

PluginListenerHandle

PropType
remove() => Promise<void>

FileDownloadProgress

PropType
progressnumber

Type Aliases

Destination

download destination , on android default is "DOWNLOAD", on ios default is "DOCUMENT"

"DOCUMENT" | "EXTERNAL" | "EXTERNAL_STORAGE" | "DATA" | "CACHE" | "LIBRARY"

Record

Construct a type with a set of properties K of type T

{ [P in K]: T; }

PermissionState

'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'

Keywords

capacitor

FAQs

Package last updated on 16 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.