234234234

ionic 文件下载

注意,只能用于http/https去下载文件

依赖:

npm install @ionic-native/downloader integrator-cordova-plugin-downloader

import { Downloader } from '@ionic-native/downloader/ngx';


constructor(private downloader: Downloader) { }

...

   var request: DownloadRequest = {
          uri: YOUR_URI,
          title: 'MyDownload',
          description: '',
          mimeType: '',
          visibleInDownloadsUi: true,
          notificationVisibility: NotificationVisibility.VisibleNotifyCompleted,
          destinationInExternalFilesDir: {
              dirType: 'Downloads',
              subPath: 'MyFile.apk'
          }
      };


  this.downloader.download(request)
              .then((location: string) => console.log('File downloaded at:'+location))
              .catch((error: any) => console.error(error));

 

posted @ 2022-06-30 09:27  你若愿意,我一定去  阅读(257)  评论(0编辑  收藏  举报
23423423423