File Download does not work on mobile phone

157 views
Skip to first unread message

Ijaja

unread,
Nov 11, 2014, 6:50:42 AM11/11/14
to google-we...@googlegroups.com
Hi,

i have implemented a file download in a gwt application.
Therefore i do a
Window.Location.assign(url); on client side with the right url to a target.

This performs a get reuqest with the context and path as desired and reaches my own implemented HttpServlet.

This sets a response header:

...

     response.setHeader("Content-Length", contentLength);
     response.setHeader("Content-Type", mimeType);
     response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
...

and writes all data to the outputstream.


This works perfect on any browser i have testet on any desktop machine.
However it seems not to work on a mobile phones browser (tested with android chrome).

Here i get a connection reset by peer on the attempt to write the content to the outputstream.
On the client side i cannot see any problems. Android reports to do a download which stays visible in the generic messages region.
Only after a long time it says, that the download failed. the reset by peer problem on server side appears immediately.


I haven't yet checked, which time exactly on writing this happens, i.e. whether he already successfully wrote some data to it.

Any ideas already about that problem?

Evan Ruff

unread,
Nov 11, 2014, 8:15:37 AM11/11/14
to google-we...@googlegroups.com
What's the mime type?

E

Ijaja

unread,
Nov 11, 2014, 10:26:36 AM11/11/14
to google-we...@googlegroups.com
the mime type i set depends on the file i am downloading.

Honestly it might be, that i have tested only one file type until now which was a jpg.

Thus i set a mimetype of 'image/jpg'.

Jens

unread,
Nov 11, 2014, 10:39:30 AM11/11/14
to google-we...@googlegroups.com
Thus i set a mimetype of 'image/jpg'.

The correct mime type is image/jpeg.

-- J. 

Evan Ruff

unread,
Nov 11, 2014, 10:46:47 AM11/11/14
to google-we...@googlegroups.com
Jens you beat me to it. I believe Android Chrome is really specific about the mime-types.

See if that works and let us know!

--
You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/Bp4FZlbFcEM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Ijaja

unread,
Nov 12, 2014, 4:39:18 AM11/12/14
to google-we...@googlegroups.com

No :-(.


This was not the problem. Same result.

I have looked in more detail.

The servlet is able to write some bytes to the response stream (example: tried to download a jpg with about 2 MB of size, servlets writes about 50 kb to the stream, then the reset by peer exception occures).

I further have no idea...

Evan Ruff

unread,
Nov 12, 2014, 7:39:34 AM11/12/14
to google-we...@googlegroups.com
Okay so it sounds like this is really not a GWT problem but a pretty typical Android<>Servlet issue. What's happening with:

1. Channels or Streams?
2. Are you using buffered components?
3. What's the chunk size and buffer size?
4. On the device, what's the connection (Wifi/Network/Emulator)
5. Have you tried with Genymotion or something similar?
6. Which HttpComponents version are you using?
7. Are you streaming manually or to a library like Picasso or something?

Thanks,

E

--

Ijaja

unread,
Nov 13, 2014, 2:42:14 AM11/13/14
to google-we...@googlegroups.com
Hi Evan,

we are getting further in little steps, but first let me answer to your points...

honestly for most things you mention i have only less idea. But let me try:

1. I do not build a channel if you mean that, i write to the HttpServletResponse.getOutputStream, without dealing channel or not (?)
2. I did not use, i wrote directly to the outputstream, mentioned above. But of course i tried now wrapping in a bufferedoutputstream -> same result :-(.
3. I don't know. In deed i had tried the chunked transfer encoding, because i read about it by a google search. I am rather sure, i did it correctly, but
    here the client (also browser on desktop machine) even didn't recognize the chunked data format and wrote the complete chunked stream as is to the file:
    he also wrote the line seperators and the chunk size informations (what did i wrong here?). I don't think that this would have solved the connection reset anyway...
   Apart from that i did not set any chunk or buffer sizes.
4. I tried downloading from the internet (underways via mobil net) and through wifi at home.
5. ???
6. I updated my gwt project to 2.6.0, this did not solve anything too. And in the library the HttpServletResponse i use is included.
7. I do not use any further library. I just use the rather plain servlet api included with gwt 2.6.0.

But... let me come to the point!

My application runs within a tomcat where the server is normal http on port 8080. For public purposes i have an apache webserver in front which uses its
own ssl certificate and can only be accessed via https ! It forwards to the local tomcat on http/8080. As said, this works fine on desktops and except downloading also on mobile phones.
So, now guess. Yesterday at home it tried download via direct access to the tomcat (none https) and it worked!

So, nice to know, but what could be the real problem and how to solve it? I do not want to download via none secure connection.

Obviously this is a problem of the android download manager which deals the download. In fact it seems that download via apache it does not recognize the header information and therefore the download fails.
My ssl certificate is not registered of course it is self signed. Might this be the problem? But what could i do. Is there a way to import my certificate in android?

But it's hard to understand. Why behaves the download manager this way, although the connection in browser is accepted by the user (if this is the problem).

Evan Ruff

unread,
Nov 13, 2014, 9:18:50 AM11/13/14
to google-we...@googlegroups.com
I'm sorry I misunderstood the target, I thought you were writing a matching Android client as well. I have had a ton of trouble with SSL and Android. It is very strict about the certificates and there are numerous stack overflow posts about getting local certs to work. Given your findings here, I'd think that it is the problem.

I would go with the buffered output stream and then research some more Android specific posts. I don't think the issue lies anywhere in GWT's implementation or packaged libraries.

Sorry I couldn't be of more help!

--

Jens

unread,
Nov 13, 2014, 10:08:46 AM11/13/14
to google-we...@googlegroups.com
My ssl certificate is not registered of course it is self signed. 

startssl.com certificates are free and are accepted by nearly every browser / OS. However their free certs are without identity validation so they only contain your domain name and nothing more.

Alternatively CloudFlare.com also provides SSL certs for their free plan that are accepted by nearly all browsers (except old ones that do not support the SNI extension). Again the cert is without identity validation. However CloudFlare is a proxy so they can technically see unencrypted data while proxying the request to your backend.

But both could help you figuring out if its an issue with your self signed cert.

-- J.

Evan Ruff

unread,
Nov 13, 2014, 10:12:29 AM11/13/14
to google-we...@googlegroups.com
Could you maybe give us some more information about your use case? Are you just serving images or are you doing some processing as well? If it's just serving images, you might be able to avoid this whole issue using a CDN with redirect or something like that?

Obviously, not an answer, but maybe an alternative implementation.

E

--

Ijaja

unread,
Nov 16, 2014, 4:10:47 PM11/16/14
to google-we...@googlegroups.com
Hello Guys,

thanks for all your help.

I have now switch to a certificate from startssl.com (thx Jens). I am glad about this, now my side is accepted and no browser seems to complain anymore about unsecure connection to an unknown certificate.
But unfortunately this also does not help for download - still same result.

I read about older android problems for android versions 2.3.x. But this seems an older issue and is not a problem anymore nowadays with android 4.x.x. So i have still no idea on how to solve this.


I have my own calendar implementation which addionally allows download of any files from my computers for good friends and family whom i have given access. There should be no restriction about data to download.
I want to solve this problem with my implementation, so i will not look for other alternatives Evan, but thx for your suggest.
One more thing about your hints/question Evan: What i do on client side in gwt is just this one command:

              String url = Location.createUrlBuilder().setPath("/cajaservice/cajaorganizer/contents/currentfile/" + result.getDownloadKey()).buildString();
              Window.Location.assign(url);

So i just redirect to perform a get request on the file to download.So maybe i do something wrong here, or there is an alternative solution on client side to do?
(maybe you have a last suggestion...?)

Ijaja

unread,
Nov 17, 2014, 4:01:35 AM11/17/14
to google-we...@googlegroups.com
Sorry guys,


i was wrong. I did not yet successfully integrate my new certificate, it was still the old one.  I was still not able to use the new certificate.
I got a p12 one and need to convert and split correctly for use in the apache http server.
I will go on trying today...
Reply all
Reply to author
Forward
0 new messages