Question

I got an error when uploading a file.

So, I get a list of files using "fileSystem.root" , and i put my selected file name to a variabel "selected_file".

And here is the code:

//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);

Everytime I upload a file, it gives an "FILE_NOT_FOUND_ERR" error. How come ??? The file is exist and I can select the file because it was retrieved by "fileSystem.root". I've tried {create: true}, {create: true, exclusive: false}, and {create: true, exclusive: true}, but nothing works.

Here is my 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)

So, any idea what is wrong?

Was it helpful?

Solution

I just solved the problem. It caused by a php function from Moodle :

error("Course module is incorrect");

OTHER TIPS

There is just a little change you have to do: not using fileEntry.fullPath but 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);

You are not reading the error correctly. The file /mnt/sdcard/c360_debug.txt is found but what is throwing the file not found exception is http://abc.php which plainly does not exist. I hope you are not trying to run a php file on your device.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top