1

按照此处的说明操作后:http: //docs.phonegap.com/en/3.0.0/cordova_file_file.md.html#FileTransfer我有以下功能:

function testUpload(imageURI) {

  var options = new FileUploadOptions();
  options.fileKey="file";
  options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
  options.mimeType="image/jpeg";

  var params = {};
  params.value1 = "test";
  params.value2 = "param";


  options.params = params;
  alert("This will show");
  alert(typeof(FileTransfer)); // "undefined"
  var ft = new FileTransfer();
  alert("This will not show...");
  ft.upload(imageURI, encodeURI("my.server/.php"), win, fail, options);

}

由于 FileTransfer() 未定义,因此上传进度不会继续。但是我不应该在调用 FileUploadOptions() 时出现错误吗?我试图谷歌搜索我需要加载的库等,但找不到任何东西。

我想我在实现插件时做错了。我已经使用以下方法加载了它:

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

当然,将它添加到我的 config.xml 中:

<feature name="File">
  <param name="ios-package" value="CDVFile" />
</feature>
<feature name="FileTransfer">
  <param name="ios-package" value="CDVFileTransfer" />
</feature>

谢谢,

4

1 回答 1

5

我终于想通了。除了已经安装的 File 插件,您还必须安装 FileTransfer 插件。

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer.git
于 2013-10-23T07:39:44.427 回答