Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cordova Phonegap文件传输错误代码返回null_Cordova_Phonegap Plugins_File Transfer_Cordova Plugins_Error Code - Fatal编程技术网

Cordova Phonegap文件传输错误代码返回null

Cordova Phonegap文件传输错误代码返回null,cordova,phonegap-plugins,file-transfer,cordova-plugins,error-code,Cordova,Phonegap Plugins,File Transfer,Cordova Plugins,Error Code,我一直在Phonegap中实现上传图片功能。 我的服务器端代码已经准备好了 我安装了插件文件和文件传输,但当我尝试将图片上传到服务器时,代码总是失败,并且总是转到fail()函数。我无法确定错误是什么,因为error.code、error.source、error.target始终为空 为什么我的错误代码为空?我不能确定这里出了什么问题,所以我真的需要你的帮助 这是我的代码: var pictureSource = navigator.camera.PictureSourc

我一直在Phonegap中实现上传图片功能。 我的服务器端代码已经准备好了

我安装了插件文件和文件传输,但当我尝试将图片上传到服务器时,代码总是失败,并且总是转到fail()函数。我无法确定错误是什么,因为error.code、error.source、error.target始终为空

为什么我的错误代码为空?我不能确定这里出了什么问题,所以我真的需要你的帮助

这是我的代码:

           var pictureSource = navigator.camera.PictureSourceType;
           var destinationType = navigator.camera.DestinationType;

                    function clearCache() {
                        navigator.camera.cleanup();
                    }

                    var retries = 0;
                    function onCapturePhoto(fileURI) {
                        var win = function (r) {
                            clearCache();
                            retries = 0;
                            alert('Done!');
                            console.log(r);
                        }

                        var fail = function (error) {
                            alert("An error has occurred: Code = " + error.code);
                            console.log("upload error source " + error.source);
                            console.log("upload error target " + error.target);
                            if (retries == 0) {
                                retries ++
                                setTimeout(function() {
                                    onCapturePhoto(fileURI)
                                }, 1000)
                            } else {
                                retries = 0;
                                clearCache();
                                alert('Ups. Something wrong happened!');
                            }
                        }

                        var options = new FileUploadOptions();
                        options.fileKey = "profilepic";
                        options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
                        options.mimeType = "image/jpeg";
                        options.chunkedMode = false;
                        options.params = {atoken : app.atoken, user_id : window.localStorage.getItem("user_id")}; // if we need to send parameters to the server request
                        var ft = new FileTransfer();
                        //alert(app.base_url + "/apiuser/updatePic");
                        ft.upload(fileURI, encodeURI(app.base_url + "/apiuser/updatePic"), win, fail, options);
                    }

                    function capturePhoto() {
                        navigator.camera.getPicture(onCapturePhoto, onFail, {
                            quality: 100,
                            sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
                            destinationType: destinationType.FILE_URI
                        });
                    }

                    function onFail(message) {
                        alert('Failed because: ' + message);
                    }

                    capturePhoto();
在config.xml中修复了它

我曾经

<gap:plugin name="org.apache.cordova.file"/>
<gap:plugin name="org.apache.cordova.file-transfer"/>

而不是

<feature name="File">
   <param name="android-package" value="org.apache.cordova.FileUtils" />
</feature>
<feature name="FileTransfer">
   <param name="android-package" value="org.apache.cordova.FileTransfer" />
</feature>

我在Android上使用phonegap 3.4.0