You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Stefan Droog <sd...@educator.eu> on 2009/05/14 16:22:02 UTC

Wicket/Jackrabbit stream PDF file to client

I want to send e.g. a PDF file to the client. It does work for JPG and Html but not for e.g PDF / PNG / TXT files.

When I try to open the file I get Adobe Reader could not open FILENAME because it is either not a supported file type or because the file has been damaged(for example, it was sent as an email attachment and wasn't correctly decoded).

Content type is "application/pdf".

Regards,
Stefan

Store the data in jackrabbit:
....
FileUpload upload = fileUploadField.getFileUpload();
Node resNode = fileNode.addNode("jcr:content", "nt:resource");
resNode.setProperty("jcr:data", upload.getInputStream());
resNode.setProperty("jcr:mimeType", upload.getContentType());
....

Stream data

Link:

Link exportCsv = new Link("downloadLink") {

                @Override
                public void onClick() {
                                IResourceStream stream = getResourceStream();

                                getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(stream).setFileName(m_fileName));
}
};
add(exportCsv);

getResourceStream returns stream

IResourceStream stream = new AbstractResourceStream() {
private InputStream m_in;
                private String m_mime;

                @Override
                public void close() throws IOException {
                                m_in.close();
                }

                @Override
                public InputStream getInputStream() throws ResourceStreamNotFoundException {
                                Session session = null;
                                try {
                                                .....
                                                //Get the inputstream from Jackrabbit repository
                                                m_in = content.getProperty("jcr:data").getStream();
                                                m_mime = content.getProperty("jcr:mimeType").getString();
                                } catch (Some exceptions)
                                } finally {
                                                session.logout();
                                }

                                return m_in;
                }

                @Override
                public String getContentType() {
                                return m_mime;
                }
};

________________________________
The information contained in this communication is confidential, intended solely for the use of the individual or entity to whom it is addressed and may be legally privileged and protected by professional secrecy. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error. This email does not constitute any commitment from Cordys Holding BV or any of its subsidiaries except when expressly agreed in a written agreement between the intended recipient and Cordys Holding BV or its subsidiaries. Cordys is neither liable for the proper and complete transmission of the information contained in this communication nor for any delay in its receipt. Cordys does not guarantee that the integrity of this communication has been maintained nor that the communication is free of viruses, interceptions or interference. If you are not the intended recipient of this communication please return the communication to the sender and delete and destroy all copies.