[Logo] Infoglue - Official Forum
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Sending binary content (e.g. excel files)  XML
Forum Index » Component Development
Author Message
tbergener

Beginner

Joined: 10/05/2010 13:44:15
Messages: 5
Offline


Hi,
I would like to send binary content (a dynamically created excel file) I created from within a component to the browser.

A scriplet inside the component does something like this:

...
byte[] excelFile = myExternalClass.createExcel();
// response.resetBuffer();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "inline; filename=Example.xls");
response.setContentLength(excelFile.length);
response.getOutputStream().write(excelFile);
...

The site node importing this component has "application/vnd.ms-excel" set as its content type.

This partially works: The excel file is sent correctly and can be saved/opened. But the filename always is "ViewPage.action" and the mimetype is not set correctly so all browsers don't recognize the file as excel.

Everything works fine if I generate CSV files instead of excel files (and set the site node's content type to "text/csv" respectively).

Is is possible to send binary content from within a component?
How can I successfully set the filename and mime type?


Best regards
Thomas
[Email]
Johan

infoglue.org

Joined: 17/05/2010 10:08:31
Messages: 2
Offline

Here's a way to set the filename of the output using Infoglue tags (which has worked for me):

<page:httpHeader name="Content-Disposition" value="inline; filename=myInterestingFilename.abc"/>

Have you tried this way to set the mimetype?

<page:deliveryContext id="dc" contentType="application/vnd.ms-excel; charset=ISO-8859-1" trimResponse="true"/>

Obviously you should use another encoding if you don't want to use ISO
I think that Infoglue might be overriding your response.setXX calls, and by using IG tags instead it should work better.

Try those and see if they help!

InfoGlue developer
Modul1 data
tbergener

Beginner

Joined: 10/05/2010 13:44:15
Messages: 5
Offline


Thanks, this works fine as long as I write text into the component.
If I write content to the output stream like this
<%
...
response.getOutputStream().write(excelFileBytes);
...
%>
the filename and content-type settings done by the page-taglib directives are broken.

We solved the problem by putting a jsp page into the infoglueDeliver*/jsp/ directory and redirecting to this page with parameters put into the session scope
(so we preserved the security needs).

Best regards
Thomas
[Email]
 
Forum Index » Component Development
Go to:   
Powered by JForum 2.1.8 © JForum Team