上传文件时出现错误。
因此,我使用“fileSystem.root”获取文件列表,并将所选文件名放入变量“selected_file”。
这是代码:
//assume ROOT = fileSystem.root and selected_file = c360_debug.txt
var options = new FileUploadOptions();
options.params = $("#myform").serialize();
ROOT.getFile(selected_file, null, function (fileEntry) {
fileEntry.file(
function (properties) {
options.fileKey="newfile";
options.fileName = properties.name;
options.mimeType = properties.type;
var ft = new FileTransfer();
ft.upload(
fileEntry.fullPath,
"http://abc.php",
function (r) {
//do something
}, onTransferError, options);
}, onFileError);
} , getRootFailed);
每次我上传文件时,都会出现“FILE_NOT_FOUND_ERR”错误。怎么会 ???该文件存在,我可以选择该文件,因为它是由“fileSystem.root”检索的。我试过 {create: true}、{create: true、exclusive: false} 和 {create: true, Exclusive: true},但没有任何效果。
这是我的 LogCat:
11-23 23:35:53.289: D/FileTransfer(9540): upload file:///mnt/sdcard/c360_debug.txt to http://abc.php
11-23 23:35:53.289: D/FileTransfer(9540): fileKey: newfile
11-23 23:35:53.289: D/FileTransfer(9540): fileName: c360_debug.txt
11-23 23:35:53.289: D/FileTransfer(9540): mimeType: text/plain
11-23 23:35:53.296: D/FileTransfer(9540): params: {}
11-23 23:35:53.296: D/FileTransfer(9540): trustEveryone: false
11-23 23:35:53.296: D/FileTransfer(9540): chunkedMode: true
11-23 23:35:53.296: D/FileTransfer(9540): headers: null
11-23 23:35:53.296: D/FileTransfer(9540): objectId: 2
11-23 23:35:53.296: D/FileTransfer(9540): String Length: 125
11-23 23:35:53.296: D/FileTransfer(9540): Content Length: 1518
11-23 23:35:56.937: E/FileTransfer(9540): {"target":"http:\/\/abc.php","source":"file:\/\/\/mnt\/sdcard\/c360_debug.txt","http_status":404,"code":1}
11-23 23:35:56.937: E/FileTransfer(9540): java.io.FileNotFoundException: http://abc.php
11-23 23:35:56.937: E/FileTransfer(9540): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:521)
11-23 23:35:56.937: E/FileTransfer(9540): at org.apache.cordova.FileTransfer.getInputStream(FileTransfer.java:480)
11-23 23:35:56.937: E/FileTransfer(9540): at org.apache.cordova.FileTransfer.access$400(FileTransfer.java:62)
11-23 23:35:56.937: E/FileTransfer(9540): at org.apache.cordova.FileTransfer$1.run(FileTransfer.java:402)
11-23 23:35:56.937: E/FileTransfer(9540): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
11-23 23:35:56.937: E/FileTransfer(9540): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
11-23 23:35:56.937: E/FileTransfer(9540): at java.lang.Thread.run(Thread.java:1019)
那么,知道有什么问题吗?