Foros de discusión

Pdf download problem with Samsung browser

Micael Ericsson, modificado hace 7 años.

Pdf download problem with Samsung browser

Regular Member Mensajes: 169 Fecha de incorporación: 11/12/12 Mensajes recientes
Liferay 6.2 website with portlets built in JSF 2.2. On the site there is a function to download a PDF-document. The functions is build as an GenericFacesPortlet with method serveResource() to create PDF on the response.

Downloading the PDF works finns on PC/MAC (IE, Chrome, Firefox, Safari) and with Chrome on IOS units. On Samsung 6 with Android 6.0.1 downloading works fine with Chrome web browser BUT fails on the default web browser. The error message on the mobile is "Downloading failed" (translated from swedish "nedladdning misslyckades").

I have tried various content settings in order for this to work, but unsuccessful so far.
- response.setContentType("application/pdf"); // This is the only setting needed for other web browsers to work

- response.setContentType("application/octet-stream");
- response.setContentLength(dokument.getDokumentInformation().length);
- response.setProperty("Content-Disposition", "inline; filename=dokument.pdf");
- response.setProperty("Content-Disposition", "attachment; filename=dokument.pdf");
- response.setProperty("Content-Length", dokument.getDokumentInformation().length + "");

Same error message every time.

Any suggestion on other response-settings or other type of configuration?
thumbnail
Kyle Joseph Stiemann, modificado hace 7 años.

RE: Pdf download problem with Samsung browser

Liferay Master Mensajes: 760 Fecha de incorporación: 14/01/13 Mensajes recientes
Hi Micael,
I tried to reproduce your issue with our example jsf-export-pdf-portlet, but I could not. I tried with both an actual Android 5.0.1 device and an emulated Andriod 6.0.1 device.

Please take a look at the jsf-export-pdf-portlet for a working example (you can even download a JSF 2.1 war and see if it works in your environment). I'd also highly recommend following its pattern and using a ResourceHandler to provide the pdf instead of overriding GenericPortlet.serveResource(). That way, your application can provide the pdf within the JSF lifecycle using the JSF API rather than utilizing both the JSF and portlet APIs to provide the pdf.

- Kyle
Micael Ericsson, modificado hace 7 años.

RE: Pdf download problem with Samsung browser

Regular Member Mensajes: 169 Fecha de incorporación: 11/12/12 Mensajes recientes
Hi Kyle

I downloaded com.liferay.faces.demo.jsf.export.pdf.portlet-3.0.0.war and installed it in our test environment.

When I try it I get the same result as my portlet.
It works with IOS and on Samsung 6 with Chrome. It doesn't work with Samsungs default web browser.
Provided images can perhaps help finding out what's wrong.
With Samsungs browser the pdf name could not be provided.
Image 1: Pdf downloaded with chrome and the name of the file is present.
Image 2: The text "<saknar namn>" and "Hämtnings misslyckades" is swedish for "missing name" and "download failed".

Plattform: Liferay 6.2
Device: Samsung 6, Android 6.0.1.

/Micael
thumbnail
Kyle Joseph Stiemann, modificado hace 7 años.

RE: Pdf download problem with Samsung browser

Liferay Master Mensajes: 760 Fecha de incorporación: 14/01/13 Mensajes recientes
Hi Micael,
After a bit of research, I've realized why I cannot reproduce your issue. It turns out that the default browser on Samsung devices is not the default Android browser. Instead it is a browser called "Samsung Internet" (or Touchwiz). Unfortunately, I cannot test this browser in an emulator (since it's built for Android on ARM and an emulated Android ARM device is unusably slow). So, all I can do is give you is some debugging advice:
  • I would recommend trying to allow the PDF to be downloaded during a GET instead of a POST. There were some bugs in the default Android browser related to downloading files during a POST. Perhaps those issues still affect Samsung Internet as well. If the download works with a GET, but not with a POST, then you have probably run into the same bug and you need to redesign your download for Samsung Internet (perhaps as suggested here). Bug reports:
  • Although it's old, you may want to try the advice of this blog. Perhaps it's still affecting the Samsung Internet browser.
  • Try using Wireshark to find out how the Samsung Internet browser is requesting the pdf and see how it differs from mobile Chrome.
  • Ask Samsung about this issue on their developer forums. Be sure to mention that Chrome mobile and the Android browsers work correctly.
Please update us on what you find and let us know if we can help somehow.

- Kyle
Micael Ericsson, modificado hace 7 años.

RE: Pdf download problem with Samsung browser

Regular Member Mensajes: 169 Fecha de incorporación: 11/12/12 Mensajes recientes
Hi Kyle

Perhaps I was not clear enough about the browser. You're correct that's the Samsung Internet application that has this problem.
According to one bug report I tried:
- setting content type to "application/octet-stream"
- setting name to document.PDF with capitals on extension.
It didn't help.

I have already posted an issue on the Samsung forum board, but no response so far.

Regarding changeing from POST to GET I am bit confused. I thought this was a GET, not a POST. Your suggestion was to change from POST to GET.

In my previous solution I had the option to set contentLength on the response. How and where do I set contentLength with the resourcehandler approach?

Regards,
Micael
thumbnail
Kyle Joseph Stiemann, modificado hace 7 años.

RE: Pdf download problem with Samsung browser

Liferay Master Mensajes: 760 Fecha de incorporación: 14/01/13 Mensajes recientes
Micael Ericsson:
According to one bug report I tried:
- setting content type to "application/octet-stream"
- setting name to document.PDF with capitals on extension.
It didn't help.

Okay, it looks like you tried the fixes from the blog/bug reports I mentioned.

Micael Ericsson:
I have already posted an issue on the Samsung forum board, but no response so far.

Ah I see the post here: http://developer.samsung.com/forum/thread/website-pdf-download-problem/201/305582?boardName=SDK&startId=zzzzz~

Micael Ericsson:
Regarding changeing from POST to GET I am bit confused. I thought this was a GET, not a POST. Your suggestion was to change from POST to GET.

Sorry, I got mixed up because the export-pdf-portlet has an unused <h:form> in it (this will be fixed as part of FACES-3027). Looks like it's using a GET to download the PDF.

Anyway, have you tried the jsf-export-pdf portlet on both public and private pages? Perhaps there is some cookie issue with the Samsung Internet browser.

Micael Ericsson:
In my previous solution I had the option to set contentLength on the response. How and where do I set contentLength with the resourcehandler approach?

Response headers can be set by overriding ResourceWrapper.getResponseHeaders() (ex: CustomerExportResource.getResponseHeaders()).

- Kyle
Micael Ericsson, modificado hace 7 años.

RE: Pdf download problem with Samsung browser

Regular Member Mensajes: 169 Fecha de incorporación: 11/12/12 Mensajes recientes
Hi Kyle

I have only tried the jsf-export-pdf on the public page. Should be the same result on private page.

The question regarding content-lengt was not where, more how to set it. I found it. I added the following row to getResponseHeaders() method:
responseHeaders.put("Content-Length", readDokument().length + "");

readDokument() returns a byte[] array of the pdf-document.

This didn't help Samsung 6/Internet combination. It also caused problem on Chrome - the loading of attachment went on for ever. And nothing happens on Ios device. Clearly not the right solution.
Micael Ericsson, modificado hace 7 años.

RE: Pdf download problem with Samsung browser

Regular Member Mensajes: 169 Fecha de incorporación: 11/12/12 Mensajes recientes
Hi again

One thing that perhaps could be of interest. With Samsung 6/Internet app combination it is possible to download a pdf-file from a site IF the file is physically on that site - i.e. a link to the file. In contrast to the problem where the pdf-file is written on the response.

/Micael
thumbnail
Kyle Joseph Stiemann, modificado hace 7 años.

RE: Pdf download problem with Samsung browser

Liferay Master Mensajes: 760 Fecha de incorporación: 14/01/13 Mensajes recientes
Hmm, that's strange. By the way, I could not reproduce your "Content-Length" error (I modified the jsf-export-pdf-portlet) with mobile Chrome or the Android browser.

To eliminate all the variables added by JSF/Liferay etc., please try to create a simple Servlet in Tomcat that will provide the PDF file and see if that works on your Samsung Browser.

- Kyle