上传文件时出错。
因此,我使用“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)
那么,知道什么是错的吗?
答案 0 :(得分:1)
我刚刚解决了这个问题。它是由Moodle的php函数引起的:
error("Course module is incorrect");
答案 1 :(得分:1)
您需要做一些改变:不使用fileEntry.fullPath但是使用fileEntry.toURI()
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.toURI(),
"http://abc.php",
function (r) {
//do something
}, onTransferError, options);
}, onFileError);
} , getRootFailed);
答案 2 :(得分:0)
您没有正确阅读错误。找到了文件/mnt/sdcard/c360_debug.txt,但抛出未找到文件的异常是http://abc.php,显然不存在。我希望你不要试图在你的设备上运行php文件。