本文介绍了未捕获ReferenceError:FileTransfer未定义(使用cordova 2.7.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to use FileTransfer to download a file from web server, code is as following:

  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: {

        }
    }
  );
 }

当我在模拟器或真实devide中运行我的应用程序时,未捕获的ReferenceError:FileTransfer未定义。

when I run my app in simulator or real devide, all hit error message: Uncaught ReferenceError: FileTransfer is not defined.

我包括cordova.js,这个错误的原因是什么?感谢。

I have included cordova.js, what is the reason for this error? thanks.

rgds
brent

rgdsbrent

推荐答案

不从浏览器工作,它会抛出新的FileTransfer未定义的错误。使用实际设备进行测试。

This plugin doesn't work from the browser, it will throw a "new FileTransfer is not defined" error. Use a real device to test.

这篇关于未捕获ReferenceError:FileTransfer未定义(使用cordova 2.7.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 07:34