【问题标题】:PhoneGap Upload Error : FILE_NOT_FOUND_ERR (code=1)PhoneGap 上传错误:FILE_NOT_FOUND_ERR(代码=1)
【发布时间】:2012-11-12 09:04:09
【问题描述】:

上传文件时出错。

所以,我使用 "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)

那么,有什么问题吗?

【问题讨论】:

    标签: android cordova upload file-not-found


    【解决方案1】:

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

    error("Course module is incorrect");
    

    【讨论】:

    • 即使我遇到了同样的错误。你能告诉我这个Moodle是什么吗??
    • 检查你的 php 函数。 Moodle 是一个 LMS(学习管理系统),参见 Moodle.org
    【解决方案2】:

    你只需要做一点改变:不使用 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);
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-07-06
        • 1970-01-01
        • 2018-03-03
        • 1970-01-01
        • 1970-01-01
        • 2023-04-06
        • 2016-05-13
        • 1970-01-01
        相关资源
        最近更新 更多