Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Biswajit Das
application/pdf is not a supported mime type
July 19, 2013 4:06 AM
Answer

Biswajit Das

Rank: New Member

Posts: 1

Join Date: July 19, 2013

Recent Posts

Hi,

I am new to Liferay. I am using struts2 in Liferay 6.1 to develop a application and tomcat as server. I have a download link in the jsp which should download a pdf file from the server.

My jsp page is contains the following:

1<td>
2   <a href='<s:url action='download'> </s:url>'>
3         Download PDF</a>
4</td>


My struts.xml is:

1<action name="download" class="com.stp.portal.view.DownloadAction">
2            <result name="success" type="stream">
3                <param name="contentType">application/pdf</param>
4                <param name="inputName">fileInputStream</param>
5                <param name="contentDisposition">attachment;filename="abc.pdf"</param>
6                <param name="bufferSize">1024</param>
7            </result>
8        </action>


My Action class is:

 1public class DownloadAction extends ActionSupport{
 2
 3    private InputStream fileInputStream;
 4
 5    public InputStream getFileInputStream() {
 6        return fileInputStream;
 7    }
 8
 9    public String execute() throws Exception {
10
11
12        fileInputStream = new FileInputStream(new File("D:\\abc.pdf"));
13        return "success";
14    }

But when I click on the download link, I get the following error:

1ERROR [Jsr168Dispatcher:38] Could not execute action
2java.lang.IllegalArgumentException: application/pdf is not a supported mime type
3    at com.liferay.portlet.MimeResponseImpl.setContentType(MimeResponseImpl.java:159)


I dont know how to solve this issue. I have googled it to find solution, bt didnot work out for me. Is this because i am using Jsr168Dispatcher? If I use Jsr268Dispatcher will it be solved ? (I found it somehere, but dont know how to change to Jsr268Dispatcher). I am stuck here. Any help is highly appreciating.
Vishal Panchal
RE: application/pdf is not a supported mime type
July 19, 2013 6:03 AM
Answer

Vishal Panchal

Rank: Expert

Posts: 277

Join Date: May 20, 2012

Recent Posts

Hi Biswajit,

AFAIK you have to set your contentType as application/pdf in your DownloadAction.

write below line before return "success" in your DownloadAction.

response.setContentType("application/pdf");

you can take reference of below post as well.
https://www.liferay.com/community/forums/-/message_boards/view_message/17420260#_19_message_17511135

hope it helps.!

Thank you,
Vishal Panchal