cordova-file-transfer Failing to upload to https server (Android only)

2,209 views
Skip to first unread message

sami...@gmail.com

unread,
Aug 15, 2016, 7:08:35 AM8/15/16
to phonegap
Hi,
After capturing a photo my app is trying to upload that photo to backend server.
I am using cordova-file-transfer  https://github.com/apache/cordova-plugin-file-transfer

It has a valid SSL certificate although a cheap one (https://www.namecheap.com/security/ssl-certificates/comodo/positivessl.aspx) [hope that's not the problem]

When I open that URL on a browser (even on Android browser) it shows correct SSL CA information.


Still it's failing to upload photos.
  • Only on Android. Works fine on iOS
  • If I change server URL to use non-ssl (port 80) it works fine on Android then.

So I am pretty sure, Android is doing something funny with the SSL/https connection.

Though, manual recommends not to use it, for testing purpose I used trustAllHosts = true

ft.upload(fileURL, encodeURI("https://backend.domain.com:4433/upload.php"), win, fail, options, true);

btw, it's not even hitting the upload.php script. I double checked that.

Please help :(

Diego La Monica

unread,
Aug 15, 2016, 11:26:41 AM8/15/16
to phon...@googlegroups.com

Hi samir, did you try to remove the encodeURI? If I remember the destination URI shoul not bè encoded.


--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
---
You received this message because you are subscribed to the Google Groups "phonegap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phonegap+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kerri Shotts

unread,
Aug 15, 2016, 1:02:08 PM8/15/16
to phonegap
1. Don't use trustAllHosts. I know, it's convenient at this stage, but it only delays the inevitable struggle with certificates. Better to get that out of the way up front than to delay it until Production. And, of course, in this case, it apparently isn't helping you at all.

2. Double check the configuration of your backend -- in particular, make sure that all necessary certificates and intermediates are present. Missing an intermediate CA can cause problems like this.

3. Let's Encrypt is free, and works on mobile devices too. Worst case if you'd can't get it working with your certificate, LE is an option.

4. What version(s) of Android are you testing on? What device(s) & manufacturer(s)?

On Monday, August 15, 2016 at 6:08:35 AM UTC-5, sami...@gmail.com wrote:
> ...

sami...@gmail.com

unread,
Aug 15, 2016, 6:39:52 PM8/15/16
to phonegap
@Diego
I haven't tried removing encodeURI. I will let you know :)

@Kerri
1) I know :( I don't wanna use trustAllHosts either.
2) Though I am not a IIS server side guru but I'm pretty sure I installed certificate correctly. What exactly is an intermediate CA ?
When I browse to backed site, CA information shows-

3) I will try Lets Encrypt, if nothing else work!

4) I used Samsung Galaxy S4 phone (Android 5.1) and Samsung Tab 7" (Android 4.4)

sami...@gmail.com

unread,
Aug 15, 2016, 9:42:33 PM8/15/16
to phonegap
@Diego
removing encodeURI didn't help :(

On Tuesday, August 16, 2016 at 1:26:41 AM UTC+10, Diego La Monica wrote:

Hi samir, did you try to remove the encodeURI? If I remember the destination URI shoul not bè encoded.

On 15 Aug 2016 13:08, <sami...@gmail.com> wrote:
Hi,
After capturing a photo my app is trying to upload that photo to backend server.
I am using cordova-file-transfer  https://github.com/apache/cordova-plugin-file-transfer

It has a valid SSL certificate although a cheap one (https://www.namecheap.com/security/ssl-certificates/comodo/positivessl.aspx) [hope that's not the problem]

When I open that URL on a browser (even on Android browser) it shows correct SSL CA information.


Still it's failing to upload photos.
  • Only on Android. Works fine on iOS
  • If I change server URL to use non-ssl (port 80) it works fine on Android then.

So I am pretty sure, Android is doing something funny with the SSL/https connection.

Though, manual recommends not to use it, for testing purpose I used trustAllHosts = true

ft.upload(fileURL, encodeURI("https://backend.domain.com:4433/upload.php"), win, fail, options, true);

btw, it's not even hitting the upload.php script. I double checked that.

Please help :(

--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
---
You received this message because you are subscribed to the Google Groups "phonegap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phonegap+u...@googlegroups.com.

Rob Willett

unread,
Aug 16, 2016, 4:20:36 AM8/16/16
to phon...@googlegroups.com
Android has issues if the intermediate CA is not installed. From memory this issue ONLY occurs when you go to production, it doesn't occur on development builds. 

You can check that your intermediate CA by using 


For our companies website (though it could be for any REST server as well). You can see that we have an intermediate certificate in our chain.  We have no worries posting this here as anybody can check any website :)


Rob




--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
---
You received this message because you are subscribed to the Google Groups "phonegap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phonegap+unsubscribe@googlegroups.com.

Kerri Shotts

unread,
Aug 16, 2016, 9:33:28 AM8/16/16
to phonegap

sami...@gmail.com

unread,
Aug 16, 2016, 6:30:57 PM8/16/16
to phonegap
Many thanks Rob. That certificate checker is very handy.
Here's what I see for my backend site (sorry I had to remove server details as I don't have permission from my client)-


It's showing- all intermediate certificates are installed (3rd line) then- 'name mismatch' (5th line)

I am confused. I thought I installed it correctly. Maybe I should contact CA support :(


Just FYI- I am using a sub-domain and bought SSL for that single subdomain only. No SSL for root domain or any other sub domain.


For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
---
You received this message because you are subscribed to the Google Groups "phonegap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phonegap+u...@googlegroups.com.

sami...@gmail.com

unread,
Aug 16, 2016, 6:32:24 PM8/16/16
to phonegap
Thanks Kerri. Those are really useful info. I haven't read all yet.
That auto installer could be very handy. I'll give it a go.
I'll keep you guys posted..

sami...@gmail.com

unread,
Aug 16, 2016, 6:50:06 PM8/16/16
to phonegap
@Rob
Ok, I found why that error on 5th line. I forgot to add port number in checker hostname. After adding port number it's showing ok. So back to square one! Certificate is installed correctly but error on Android :(

Rob Willett

unread,
Aug 17, 2016, 1:37:31 AM8/17/16
to phon...@googlegroups.com

It's difficult to help when there is so little information provided.

We're scrambling in the dark.

Rob

sami...@gmail.com

unread,
Aug 17, 2016, 6:22:36 AM8/17/16
to phonegap
What info do you need

Rob Willett

unread,
Aug 17, 2016, 4:43:54 PM8/17/16
to phon...@googlegroups.com
I've read through this email trail again and I'm still struggling to see an error message or something that says what the problem actually is, apart from you can't make some sort of connection on Android. Its not clear to me what is going on as there seems to be at least two issues, one of which was a server port issue and one the first issue (which is still vague to me).

So what would help me is a 

1. Clear summary of what the issue currently is now. Asking us to go through an email trail to try and deduce the problem is hard work.

2. What's the actual error message? Show us the output of Chrome.

3. Have you tried to make a connection using a standalone program, I use Paws or Perl or anything to check that my SSL connection is actually working. Google has something now to check connections. If it works standalone then you know there's a chance it will work with your code.

Don't forget we know nothing whatsoever about what you are doing. We have seen one line of code and AFAICT not a single error message. There is a page pinned to the start of this group that shows the sort of information that should be provided if you need help. many people have contributed to it and its worth reading.

You need to put the time in to allow us to help you.

Rob 




For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
---
You received this message because you are subscribed to the Google Groups "phonegap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phonegap+unsubscribe@googlegroups.com.

sami...@gmail.com

unread,
Aug 18, 2016, 6:09:58 AM8/18/16
to phonegap
@Rob

1. Clear summary of what the issue currently is now. Asking us to go through an email trail to try and deduce the problem is hard work.
Don't worry about port number thing. That was a mistake I made during testing only.
All details are below-

2. What's the actual error message? Show us the output of Chrome.
If there was an error message, I wouldn't probably need to post here anything! 
There's absolutely no error showing! At least not on the tools I am using for debugging (Chrome, Fiddler, Charles)
Attached screenshots from chrome://inspect 
Console shows 3 lines only. I used console.log to indicate when it reach at the end of function (means something didn't break it) and other two shows file upload progress (I was hoping more than 2 lines though!)
Network tab also confirms- it's not even calling upload.php on remote server (backend)


3. Have you tried to make a connection using a standalone program, I use Paws or Perl or anything to check that my SSL connection is actually working. Google has something now to check connections. If it works standalone then you know there's a chance it will work with your code.
I am not familiar with this. I will google.

Don't forget we know nothing whatsoever about what you are doing. We have seen one line of code and AFAICT not a single error message. There is a page pinned to the start of this group that shows the sort of information that should be provided if you need help. many people have contributed to it and its worth reading.
I understand your point of view. I worked in an IT support role many years and we wanted as much info as possible to be able to help.
but in this case, I thought it might be a known issue...could be an easy fix/trick.
Clearly it's not! Now I am thinking- this could be a bug in the plugin/Android.


Details of the issue
  1. File transfer plugin cannot upload to server.
  2. Only when HTTPS. non ssl http is fine.
  3. Double checked certificate on my production server. No issue.
  4. Android only. Works fine on iOS. So I don't think there's anything wrong within my code.
  5. Used Fiddler & Charles to confirm, app is not even calling upload.php
  6. Doesn't show any error (using Chrome debugger)

My extended tests
  1. At first I thought my SSL certificate wasn't installed properly. So I checked using https://www.ssllabs.com/ssltest/ (btw, best in my opinion) It found some vulnerabilities. Fixed them all. Now it's showing no issue (Grade A) Still original issue exists!
  2. As I used a subdomain and custom port; for testing purpose I moved all scripts in backend to root folder/site with default 443 port. (https://domain.com/upload.php) (again, correct certificate) Still original issue exists!
  3. Now I used a fresh cordova app (HelloWorld) and just installed camera+fileTransfer plugin & relevant codes. No other codes! Still original issue exists! (worked fine on iOS)
  4. I used different version of Android, different devices.
  5. I tried https://github.com/hypery2k/cordova-certificate-plugin to trust unsecure cert (testing purpose) but no luck.
  6. I searched google over and over...saw many examples. All used HTTP protocol. Made me wonder- has anyone successfully implemented FileTransfer upload on Android and sending file over SSL ??




My assumptions-
  1. Could be a bug in the plugin or Android itself.
  2. I read somewhere, unlike other browsers, Android is very strict on SSL certificate checking. Maybe it doesn't like my cheaper certificate. Maybe it requires one of those $100+ certificates!!
  3. I am about to give up and use HTTP for Android only !!
Screen Shot 2016-08-18 at 9.13.16 AM.png
Screen Shot 2016-08-18 at 9.12.35 AM.png

Rob Willett

unread,
Aug 18, 2016, 8:05:29 AM8/18/16
to phon...@googlegroups.com
Mmmm....

I looked at the plugin and it talks about certificates so I assume that it works with SSL certficates. The docs look well written and there are loads of patches so it looks like a decent supported plugin. 

The fact that you don't *appear* to have any output when you go to https makes me think that there is a bug somewhere in your code or the plugin.

The fact it works on IOS doesn't mean your code is right. It's probably right, but there could still be a config issue. IOS and Android SSL handling is different. 

Have you looked at adb logcat to see if anything odd is on your device. I'd love to see a network sniffer on this and see if its actually making even the start of a network connection. We use PAW on a Mac to test REST API's but you could tests with any number of other apps, Google Chome has Postman which we have but have never used. 

Normally I would expect to see a failed network transaction in the Network window under Chrome You don't even appear to have that. 

What I'd do:

1. Check the network connection using Postman (or similar). The fact that the certificates work is nice but is still not proof it works. 

2. Change your code to use http and have a look at the network traffic under Chrome so you can see a working set of transactions.

3. Post the question on the plugin issues board and ask them the simple question does https work under Android.

4. have a look at adb logcat and see if there is anything untoward.

I assume you have configured CORS etc on your app?

Rob

--

shrijan piya

unread,
Sep 5, 2016, 11:29:31 AM9/5/16
to phonegap
have you found soln to this 
i am facing exactly same issue

Kerri Shotts

unread,
Sep 5, 2016, 12:15:31 PM9/5/16
to phonegap
@shrijan piya,

Please read the welcome text for this group and reply back with the requested information. As it is right now, you've not provided enough information for us to be of any help.

On Monday, September 5, 2016 at 10:29:31 AM UTC-5, shrijan piya wrote:
...

Arshak Alexanyan

unread,
Dec 6, 2016, 1:56:06 AM12/6/16
to phonegap
HI, 

I have same issue, fileupload was not working on android over https.
I've set chunkedMode = false and it's fix my issue

 var options = new FileUploadOptions();
 options.fileKey = "file";
 options.chunkedMode = false;

phonegap version: 6.2.9
filetransfer plugin version: 1.5.1

Jan Barandun

unread,
Dec 7, 2016, 4:03:49 PM12/7/16
to phonegap
Hi
I also have exact the same issue.
chunkedMode = false fixed the issue on iOs but not on android.
i had to switch to non SSL connection to make the file upload.

Working witdh cordova 6.4.0, cordova-plugin-file-transfer 1.6.0

Arshak Alexanyan

unread,
Dec 8, 2016, 1:40:06 PM12/8/16
to phonegap
On which version of Android you've tested ?
I did on Android 7 and 7.1

jcesarmobile

unread,
Dec 9, 2016, 3:45:18 AM12/9/16
to phonegap
There has been some issues with latest release of the plugin. I think they are already fixed in github repo. You can install it from there directly or wait a few days until it's released

hitesh....@switchme.in

unread,
Feb 18, 2018, 9:45:21 PM2/18/18
to phonegap
Did anyone find the solution to the problem, i am facing the same issue , the upload function works fine on local server, but doesn't even hit the backend on local server.

Rob Willett

unread,
Feb 19, 2018, 12:06:06 PM2/19/18
to phon...@googlegroups.com
This thread is nearly 18 months old. Suggest you start a new one, rather than resurrect old ones.

--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
---
You received this message because you are subscribed to the Google Groups "phonegap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phonegap+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages