属性"下载"在类型"传输"上不存在。在离子 2 文件传输



我在我的应用程序中使用ionic 2文件传输本机插件从服务器下载Sample.csv文件。

面对以下错误消息:

属性"下载"在类型"传输"上不存在。

  const fileTransfer = new Transfer();
  let url = 'url to the server file';   
  console.log(url);
  fileTransfer.download(url, cordova.file.dataDirectory + 'Sample.csv').then((entry) => {
      console.log('download complete: ' + entry.toURL());
   }, (error) => {
                    console.log("No file to download");
   });

并且在控制台中未定义获取科尔多瓦。

谁能帮我解决这个问题?

你必须导入这个。

import { Transfer, FileUploadOptions, TransferObject } from '@ionic-native/transfer';
import { File } from '@ionic-native/file';

之后像这样注入它。

constructor(private transfer: Transfer, private file: File) { }

声明如下。

const fileTransfer: TransferObject = this.transfer.create();

像这样使用。

// Download a file:
fileTransfer.download(..).then(..).catch(..);

您可以在此处参考官方文档

最新更新