npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

capacitor-plugin-filedownload

v2.0.0

Published

a file download plugin for capacitor3.0+

Downloads

428

Readme

capacitor-plugin-filedownload

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>

| Param | Type | | ------------- | ------------------------------------------------------------------- | | options | FileDownloadOptions |

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

| Param | Type | | ------------------ | -------------------------------------------------------------------------------------------- | | eventName | 'downloadProgress' | | listenerFunc | (progress: FileDownloadProgress) => void |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


Interfaces

FileDownloadResponse

| Prop | Type | | ---------- | ------------------- | | path | string |

FileDownloadOptions

| Prop | Type | Description | Default | | ------------------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------ | -------------------------------------------------------------------- | | url | string | | | | fileName | string | | | | destination | Destination | Download file destination | ios default: Document android default: External Storage | | headers | Record<string, string> | request headers, when headers has value, url must be a http request with POST method | | | body | Record<string, unknown> | request body, when body has value, url must be a http request width POST method | | | downloadTitle | string | Downloader Title, Only Android | | | downloadDescription | string | Downloader Description, Only Android | |

CancelStatus

| Prop | Type | | ---------------- | -------------------- | | isCanceled | boolean |

PermissionStatus

| Prop | Type | Description | | ------------- | ----------------------------------------------------------- | ---------------------------------------------------------------------------- | | storage | PermissionState | prompt: 首次申请,询问。 prompt-with-rationale: 每次都询问。 granted: 已获取权限。 denied:权限已拒绝。 |

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |

FileDownloadProgress

| Prop | Type | | -------------- | ------------------- | | progress | number |

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'