5

I'm currently trying to upload a picture to a server with the FileTransfer.upload() method of PhoneGap. It works fine on the iPhone Simulator over Wifi, but fails on an Android phone over 3G or Wifi.

alert(error.code) returns '3' but I couldnt find out what this error code is.

Did anybody stumbled upon the same problem and managed to solve it ? Please help.

Titouan de Bailleul
  • 12,920
  • 11
  • 66
  • 121
  • http://stackoverflow.com/questions/11783985/phonegaps-filetransfer-upload-throwing-error-code-3-on-android/19268066#19268066 – Tsybulsky Serg Oct 09 '13 at 09:33

2 Answers2

17

Error code 3 is a connection error. Recently we made chunked mode the default for uploading on Android. Try setting your options object to have a chunked mode that is false.

var options = FileUploadOptions();
options.chunkedMode = false;
Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
  • Thanks for your answer. I just tried it but it still returns '3'. Any other idea ? – Titouan de Bailleul Dec 15 '11 at 16:14
  • 2
    Is there anyway to display more information about this error. Something better than error.code. – Titouan de Bailleul Dec 15 '11 at 17:18
  • 1
    By chance are you trying to upload to a https site using a self signed cert? For logging what do you see in "adb logcat" or on the server logs? – Simon MacDonald Dec 15 '11 at 18:33
  • Yes, I am actually uploading to an https site. I can't tell you right now what are the logs but I will as soon as I can get my hands on a Android Simulator. Thank you – Titouan de Bailleul Dec 15 '11 at 18:47
  • 3
    If you are uploading to a https site with a self signed certificate you need to add an extra parameter on upload. Try upload(filePath, server, successCallback, errorCallback, options, true); that extra "true" at the end tells upload to accept self signed certs. – Simon MacDonald Dec 16 '11 at 14:38
  • Being on holidays for the next two weeks, I can't test your solutions for the moment. Anyway, thank you very much. I'll get back to you asap. Thanks again – Titouan de Bailleul Dec 17 '11 at 14:31
  • Hi Simon, First - thank you for that answer. 1. I have spent the entire day until I got to your answer. Can you guys add that to cordova file Android (4.*) Quirk (http://docs.phonegap.com/en/2.0.0/cordova_file_file.md.html#FileTransfer) to save users time in the future? 2. What are the benefits from running `chunkedMode=true`? Should I run my ios version of the app with that settings? – Roei Bahumi Sep 06 '12 at 14:33
  • If anyone had problems with $_POST and $_FILES being empty on server side, setting chunkedMode to false helped me – BozanicJosip Sep 22 '16 at 19:47
12

Today, I tried Simon MacDonald's answer and it worked, so for those who have the same problem. It's certificate related and can be solved simply by adding a 'true' parameter at the end of the upload() function like below :

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

Thank you !

PS: That extra "true" at the end tells upload to accept self signed certs.

Viral Patel
  • 32,418
  • 18
  • 82
  • 110
Titouan de Bailleul
  • 12,920
  • 11
  • 66
  • 121