Phonegap's FileTransfer.upload() throwing error code 3 on Android

这一生的挚爱 提交于 2019-11-30 07:02:30

问题


I am working on uploading a picture to a server. I am able to successfully upload an image using iOS but when i try on android I get the error code 3. Currently using phonegap cordova 1.8.1.

I already tried adding true to the parameters

upload(filePath, server, successCallback, errorCallback, options, **true**);

and adding this

options.chunkedMode = false;

My AndroidManifest file contains:

<uses-permission android:name="android.permission.INTERNET" />

My cordova.xml file contains:

<access origin="*"/>

Am I missing something?

Thanks


回答1:


The issue probably is not in Phonegap. if the server is a Windows based server, try using another server. Also, don´t forget to add these lines:

var options = new FileUploadOptions();
options.chunkedMode = false;
options.headers = {
      Connection: "close"
   };



回答2:


add code:

var op;
op = new FileUploadOptions();

op.headers = {
    Connection: "close"
};

After adding this - code started to work well with no errors. A bit more detailed description: http://grandiz.com/phonegap-development/phonegap-file-transfer-error-code-3-solved Hope that helps!




回答3:


This happened to me too. You should specify chunkedMode=false (http://stackoverflow.com/questions/8522729/phonegap-filetransfer-upload-fails-on-android)

var options = FileUploadOptions();
options.chunkedMode = false;



回答4:


These are steps I used to overcome this problem:

Added the following options:

options.chunkedMode = false;
options.headers = {
      Connection: "close"
   };

But more important was the fact that I was using Genymotion as the emulator for testing. Uploading the image to localhost was not working because the emulator was running in a VM and localhost meant the VM's localhost and not the localhost of your web server.

So instead of uploading to 'localhost', you should upload to:

http://10.0.2.2 

and add the following line to your config.xml:

<access origin="10.0.2.2" subdomains="true"/>

I tested it and its working like a charm. Took me 3 days to get this working though.




回答5:


This is an unfixed bug in the phonegap library, since there were no bug fixes, i had to get it work by my work around (Basically reupload on every alternate failure):

ft.upload(path,
          encodeURI("http://yourdomain.com/upload.php"),
            function(result) {
                alert("Uploaded");
            },
            function(error) {
                ft.upload(path,
                encodeURI("http://yourdomain.com/upload.php"),
                function(result) {
                    alert("Uploaded");                  
                },
                function(error) {
                    alert("Error uploading image");
                },
                { fileName: name, fileKey: "file", mimeType: "image/jpeg", chunkedMode: false }, true);     
            },
            { fileName: name, fileKey: "file", mimeType: "image/jpeg", chunkedMode: false }, true);



回答6:


I've asked Telerik about this issue that I experience with AppBuilder. According to their response it might be a bug in Cordova (I'm using 3.2).

They recommend updating to the latest FileTransfer library (also update all the dependencies) and see if that solves your issue. I actually ran into another problem compiling the new libraries.

I recommend trying that and see if that works for you.




回答7:


This could also be a reason, and solved it for me:

iOS 9 and OSX 10.11 require TLSv1.2 SSL for all hosts you plan to request data from unless you specify exception domains in your app's Info.plist file.

(CFNetwork SSLHandshake failed iOS 9)




回答8:


You can try either of these:

Set android:debuggable="true" in the <application> tag of your AndroidManifest.xml file.

Set <access origin=".*"/> instead of just the * as it's recommended in the comments section as follows:

<!-- <access origin="https://example.com" /> allow any secure requests to example.com -->
<!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www -->
<!-- <access origin=".*"/> Allow all domains, suggested development use only -->


来源:https://stackoverflow.com/questions/11783985/phonegaps-filetransfer-upload-throwing-error-code-3-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!