capacitor-plugin-filedownload
A file download plugin for capacitor3.0+
Install
npm install @himeka/capacitor-plugin-filedownload
npx cap sync
eg:
import { FileDownload } from "@himeka/capacitor-plugin-filedownload";
FileDownload.download({
uri: "http://www.xxxxx.com/file/rvh.apk",
fileName: "release.apk"
}).then((res) => {
console.log(res.path);
}).catch(err => {
console.log(err);
})
/* Not implemented
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>
Returns: Promise<FileDownloadResponse>
addListener('downloadProgress', ...)
addListener(eventName: 'downloadProgress', listenerFunc: (progress: FileDownloadProgress) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
Interfaces
FileDownloadResponse
FileDownloadOptions
Prop |
Type |
uri |
string |
fileName |
string |
PluginListenerHandle
Prop |
Type |
remove |
() => Promise<void> |
FileDownloadProgress
Prop |
Type |
progress |
number |