1

我很难让 FileTransfer 在 Cordova 1.6.0 中工作。我在早期版本中没有尝试过,所以我不知道这是否是一个新问题。

var options = new FileUploadOptions();
options.fileKey = "file";

var ft = new FileTransfer();
ft.upload( 
    imageURLToLocalFile, 
    urlToMyServiceEndpoint, 
    successhandler,
    errorhandler,
    options
);

在我看到的 Xcode 控制台中。

*** WebKit discarded an uncaught exception in the
webView:decidePolicyForNavigationAction:request:frame:decisionListener: 
delegate: <NSRangeException> ***
 -[JKArray objectAtIndex:]: index (1) beyond bounds (1)

在我看来,当 Cordova exec 函数调用本机 Filehandler 函数时,会发生这种情况,但我不知道如何解释错误消息。

我有点怀疑创建错误的调用,即 Cordova 文件中的 FileTransfer.prototype.upload 函数。我的 1.6.0 版本是:

exec(
    successCallback, 
    errorCallback, 
    'FileTransfer', 
    'upload', 
    [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode]
);

而旧的 1.5.0 版本是:

Cordova.exec(
    successCallback,
    errorCallback,
    'org.apache.cordova.filetransfer', 
    'upload', 
    [options]
);
4

2 回答 2

2

这是 Cordova 1.6.x 中的一个错误,将在 Cordova 1.7.0 (https://issues.apache.org/jira/browse/CB-543) 中解决。

解决方法是手动指定所有选项(fileName、fileKey 等),因为框架错误地将它们视为必需的。

所以:

var options = new FileUploadOptions();
options.fileKey = "file";

变成:

var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = "image.jpg";
options.mimeType = "image/jpeg";
options.chunkedMode = true;
options.params = {}; // This line is untested as I have actual params

富有的

于 2012-04-20T05:01:29.963 回答
0

上传方式好像变了。我有类似的问题,通过在选项之后添加 true 来解决:

var ft = new FileTransfer();
ft.upload(

  imageURLToLocalFile, 
  urlToMyServiceEndpoint, 
  successhandler,
  errorhandler,
  options,
  **true**
);
于 2012-04-16T07:46:36.840 回答