0

上传文件时出现错误。

因此,我使用“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)

那么,知道有什么问题吗?

4

3 回答 3

1

我刚刚解决了这个问题。它是由Moodle的 php 函数引起的:

error("Course module is incorrect");
于 2012-11-26T19:15:53.753 回答
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);
于 2014-04-16T11:41:36.287 回答
0

您没有正确读取错误。找到了文件 /mnt/sdcard/c360_debug.txt,但是抛出文件未找到异常的是http://abc.php,它显然不存在。我希望您不要尝试在您的设备上运行 php 文件。

于 2012-11-26T04:05:56.380 回答