Download a file from a mobile devices don't work


I have problem with file being downloaded from a mobile device is recognised as unknown.

Below is the code i have used, it works on a PC browser but when I try to access the app via a mobile device, the file gets downloaded as unknown and eventually the download will be unsuccessful.

FileResource resource = new FileResource(new File(“c:\test\test.pdf”));
DownloadStream stream = resource.getStream();
stream.setParameter(“Content-Disposition”, “attachment; filename=test.pdf”);

FileDownloader fileDownloader = new FileDownloader(resource);

The mobile device I am using to test:
Device: Sony Xperia M2
OS: android 4.3
Browser: Chrome v37

Many Thanks.

After investigating i am getting the following error on the server log:

Oct 07, 2014 12:11:47 PM com.vaadin.server.DefaultErrorHandler doDefault
ClientAbortException: Connection reset
at org.apache.catalina.connector.OutputBuffer.doFlush(
at org.apache.catalina.connector.OutputBuffer.flush(
at org.apache.catalina.connector.CoyoteOutputStream.flush(
at com.vaadin.server.DownloadStream.writeResponse(
at com.vaadin.server.FileDownloader.handleConnectorRequest(
at com.vaadin.server.ConnectorResourceHandler.handleRequest(
at com.vaadin.server.VaadinService.handleRequest(
at com.vaadin.server.VaadinServlet.service(
at com.vaadin.addon.touchkit.server.TouchKitServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.valves.ErrorReportValve.invoke(
at org.apache.catalina.valves.AccessLogValve.invoke(
at org.apache.catalina.core.StandardEngineValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.apache.coyote.http11.AbstractHttp11Processor.process(
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$
Caused by: Connection reset
at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(
at org.apache.coyote.http11.InternalOutputBuffer.flush(
at org.apache.coyote.http11.AbstractHttp11Processor.action(
at org.apache.coyote.Response.action(
at org.apache.catalina.connector.OutputBuffer.doFlush(
… 31 more

What could cause this to happen?

I get a similar problem, have you fix this? Could your tell me why this problem appear? Thanks

The code that i have provided works but you will have to check if your app is not connecting to a proxy server.

In order to solve this problem:

  • For iOS it does not allow you to initialize the download, you will have to open the file in a new tab: e.g:
Link link = new Link(caption, new StreamResource(yourStreamSource));
  • For chrome on the Android it does not work as there is a bug with the Android native file downloader. For more info refer to this ticket
  • Firefox browser on the Android works fine

Hope this will help you resolve your problem.

Thanks you very much, my project only work for the iOS, is that you mean FileDownloader cannot work, if I use IOS devices?

I am not too familiar with IOS developement, but i have read about ISO native app have their own specific storage area only, only the app has access to. I think by design Apple lock down on storage area on the phone I am not 100% sure.

It depends on your requirement, if your app is web base then FileDownloader is not appropriate as Safari browser does not have the ability to download files from the web, the best you can do is open the file on the browser.

OK, I get it. Thank you very much.