【问题标题】:Uncaught ReferenceError: FileTransfer is not defined (using cordova 2.7.0)未捕获的 ReferenceError:未定义 FileTransfer(使用 cordova 2.7.0)
【发布时间】:2013-05-08 14:00:22
【问题描述】:

我想使用 FileTransfer 从网络服务器下载文件,代码如下:

  function downloadFile(url) {
     var fileTransfer = new FileTransfer();
     var uri = encodeURI(url);
     var filepath="www/download/";

     fileTransfer.onprogress = function(progressEvent) {
        if (progressEvent.lengthComputable) {
          loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total);
        } else {
          loadingStatus.increment();
        }
     };

    fileTransfer.download(
      uri,
      filePath,
      function(entry) {
        console.log("download complete: " + entry.fullPath);
      },
      function(error) {
        console.log("download error source " + error.source);
        console.log("download error target " + error.target);
        console.log("upload error code" + error.code);
      },
      false,
      {
        headers: {

        }
    }
  );
 }

当我在模拟器或真实设备中运行我的应用程序时,都会出现错误消息:Uncaught ReferenceError: FileTransfer is not defined。

我已经包含了cordova.js,这个错误的原因是什么?谢谢。

rgds 布伦特

【问题讨论】:

  • 一开始你设置filepath,但后来在.download()中你使用filePath。这只是复制/粘贴错误吗?
  • 是的,复制/粘贴错误,应该是“文件路径”。
  • 错误发生在以下行:“var fileTransfer = new FileTransfer();”。
  • 有什么解决办法吗?

标签: android cordova


【解决方案1】:

此插件无法在浏览器中运行,它会抛出“未定义新文件传输”错误。使用真机进行测试。

【讨论】:

    【解决方案2】:

    你需要安装phonegap插件:

    $phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git
    $phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer.git
    

    如果您已经安装,可能需要重建 phonegap 平台:

    $phonegap build android
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-23
      • 2020-11-20
      • 2023-01-23
      • 2016-11-03
      • 2011-01-05
      • 2016-01-02
      • 2013-10-06
      • 2016-12-17
      相关资源
      最近更新 更多