Stream BLOB contents

I’m trying to stream the contents of a BLOB column in a database to the browser as a file. The contents of the BLOB is a gzipped XML file. This works in IE7 but not in Firefox 3.5. Here is how it’s implemented. I created a DownloadResource class:

public class DownloadResource extends StreamResource {
    private final String filename;

    public DownloadResource(byte[] fileBytes, String fileName, Application application) {
        super(new ByteStreamResource(fileBytes), fileName, application);
        this.filename = fileName;

    public DownloadStream getStream() {
        DownloadStream stream = new DownloadStream(getStreamSource().getStream(), "text/xml", filename);
        stream.setParameter("Content-Disposition", "attachment;filename=" + filename);
        stream.setParameter("Content-Encoding", "gzip");
	return stream;

    private static class ByteStreamResource implements StreamResource.StreamSource {
        private final InputStream inputStream;

        public ByteStreamResource(byte[] fileBytes) {
            inputStream = new ByteArrayInputStream(fileBytes);

        public InputStream getStream() {
            return inputStream;

Then a button that lives in a table to stream the contents:

addGeneratedColumn("xml", new ColumnGenerator() {
            public Component generateCell(Table source, Object itemId, Object columnId) {
                final Object id = getContainerProperty(itemId, "id").getValue();
                final byte[] xml = (byte[]
) getContainerProperty(itemId, "xml").getValue();
                Button dlButton = new Button();
                dlButton.setIcon(new ThemeResource("icons/16/document.png"));
                dlButton.addListener(new Button.ClickListener() {

                    public void buttonClick(ClickEvent event) {
                        DownloadResource dlResource = new DownloadResource(xml, (id + ".xml"), app);
                        app.getMainWindow().open(dlResource, "_blank");

                return dlButton;

What is happening on a FF ?

I get the dialog box to save or open the file, but no matter what option I pick nothing happens. Whether I click Open or Save, the dialog box just disappears and I don’t receive the file.

Hm, do not see anything bad in your code snippet… Several similar parts of such code is used in my projects and woks well in FF. I’ll try to reproduce your example line by line later this evening to find any potential problems.

BTW, the same app and the same item in a table downloads well in IE, right ?

Upd: could it be any firewall or content/ad blocker plugin that triggers ?

I tried again in FF with all Add-ons disabled and still no luck. Same exact behavior as described before.

Why do you specify in the header it’s gzipped and that the doc type is text/xml ?
Normally you only specify that, when you wish the browser to handle it in a special way.

I think not adding the gzipped header and serving it as application/octet-stream will prevent
the browser (or any proxy) to do some unzipping or trying to display XML stuff.


The reason I do that is because the BLOB is a gzipped XML file. By specifying those properties in the header the browser knows to automatically unzip the file and that the unzipped file is of type text/xml. Again this works fine in IE.