Phonegap:FileTransferError.FILE_NOT_FOUND_ERR

时间:2017-05-06 13:50:46

标签: javascript cordova phonegap

我正在使用Phonegap文件传输插件将图片上传到服务器。但是我收到错误代码:1(FileTransferError.FILE_NOT_FOUND_ERR)。我用POSTMAN测试了我的服务器代码,我可以成功上传和映像。但是我在插件中遇到了这个错误。这是我的代码。该文件是从“camera_image.src”声明的,当我将其附加到动态图像的src时,我可以看到该图像。任何贡献?这段代码怎么不完美?

                var fileURL = camera_image.src;     
                alert(fileURL); 
                var win = function (r) {
                    temp.push(r.response);
                    statusDom.innerHTML = "Upload Succesful!";
                }

                var fail = function (error) {
                    alert("An error has occurred: Code = " + error.code + " | Source:" + error.source + " | Target:" + error.target );
                    statusDom.innerHTML = "Upload failed!";
                }

                var options = new FileUploadOptions();
                options.fileKey = "properties_photo";
                options.fileName=fileURL.substr(fileURL.lastIndexOf('/') + 1);
                options.headers = {
                    Connection: "close"
                };

                var params = {};
                params.value1 = "test";
                params.value2 = "param";

                options.params = params;

                var ft = new FileTransfer();

                statusDom = document.querySelector('#status');
                ft.onprogress = function(progressEvent) {
                            if (progressEvent.lengthComputable) {
                        var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100);
                    statusDom.innerHTML = perc + "% uploaded...";
                            console.log(perc);
                            } else {
                                    if(statusDom.innerHTML == "") {
                                    statusDom.innerHTML = "Loading";
                            } else {
                                    statusDom.innerHTML += ".";
                            }
                        }
                    };
                ft.upload(fileURL, encodeURI("http://cloud10.me/clients/itsonshow/app/image_upload_process.php"), win, fail, options);  

1 个答案:

答案 0 :(得分:1)

我遇到此问题是因为要上传的文件的路径或文件名中有空格。

您需要确保插件未在URL中传递带有%20的fileURL。