Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 988
user1572156 Avatar asked Aug 02 '12 18:08

user1572156


4 Answers

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"
   };
like image 61
Marcio Ota Avatar answered Oct 14 '22 20:10

Marcio Ota


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!

like image 44
Tsybulsky Serg Avatar answered Oct 14 '22 20:10

Tsybulsky Serg


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;
like image 2
Roei Bahumi Avatar answered Oct 14 '22 20:10

Roei Bahumi


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.

like image 2
Suyash Sumaroo Avatar answered Oct 14 '22 19:10

Suyash Sumaroo