Example usage for com.liferay.portal.kernel.portlet PortletResponseUtil sendFile

List of usage examples for com.liferay.portal.kernel.portlet PortletResponseUtil sendFile

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.portlet PortletResponseUtil sendFile.

Prototype

public static void sendFile(PortletRequest portletRequest, MimeResponse mimeResponse, String fileName,
            InputStream inputStream, int contentLength, String contentType) throws IOException 

Source Link

Usage

From source file:com.liferay.privatemessaging.portlet.PrivateMessagingPortlet.java

License:Open Source License

public void getMessageAttachment(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long messageId = ParamUtil.getLong(resourceRequest, "messageId");
    String fileName = ParamUtil.getString(resourceRequest, "attachment");

    MBMessage message = MBMessageLocalServiceUtil.getMessage(messageId);

    if (!PrivateMessagingUtil.isUserPartOfThread(themeDisplay.getUserId(), message.getThreadId())) {

        throw new PrincipalException();
    }// w w w.  j av  a 2s  .  c o m

    FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(message.getGroupId(),
            message.getAttachmentsFolderId(), fileName);

    PortletResponseUtil.sendFile(resourceRequest, resourceResponse, fileName, fileEntry.getContentStream(),
            (int) fileEntry.getSize(), fileEntry.getMimeType());
}