我正在使用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);

最佳答案

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

您需要确保未向插件传递URL中包含%20的fileURL。

关于javascript - 电话空档:FileTransferError.FILE_NOT_FOUND_ERR,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43821240/

10-12 06:45