I'm currently facing a problem when use JSF download file on mobile.
Everything works fine as long as I use my desktop browser, but as soon as I change to my mobile device,I get a .html file which contains the source code.
Here is my download method
public StreamedContent getDrawing() throws Exception {
DocumentFile documentFile = (DocumentFile) getViewScope("documentFile");
if (documentFile != null) {
byte[] content = documentFileService.download(documentFile.getId());
InputStream stream = new ByteArrayInputStream(content);
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
externalContext.setResponseContentLength(content.length);
StreamedContent content2 = new DefaultStreamedContent(stream,
URLEncoder.encode(documentFile.getFilename(), "UTF-8"));
facesContext.responseComplete();
return content2;
}
return null;
}
This is my downloadButton
<h:commandButton value="fileDownload">
<p:fileDownload value="#{controller.drawing}"
contentDisposition="attachment"></p:fileDownload>
<f:ajax disabled="true" />
</h:commandButton>
I had saw this same issue,but it can not solve my problem
Now I don't know how to solve this problem