Streamresource getting open in the same window for IE9

Hi,

We want to download files from vaadin 7 application.

We are reading file content & creating Streamresource from that content.

We have achievevd download functionality in Chrome 33 & Mozilla Firefox however IE 9 is opening the streamresource in the same window instead of downloading the file nad when user tries to go back with browser’s back button he is thrown out of application means vaadin session is dosconnected.

following is the code snippet.

                                   final ByteArrayInputStream arrayInputStream = (ByteArrayInputStream) contentMap.get("content");
                                   final String documentName = (String) contentMap.get("object_name");
                                
                                    StreamResource streamResource = new StreamResource(
                                            new StreamResource.StreamSource() {
                                                public InputStream getStream() {
                                                    return arrayInputStream;
                                                }
                                            },documentName);

                                        streamResource.setMIMEType("application/content-stream");
                                        Page.getCurrent().open(streamResource, null, false);

Expecting help on this.

I used your code with small changes to compile it. In IE7+Win7, it shows a popup asking if I want to open or save the file. Could you give more details about this problem?

    StreamResource streamResource = new StreamResource(
            new StreamResource.StreamSource() {
                public InputStream getStream() {
                    return new ByteArrayInputStream(new byte[128]

);
}
}, “name”);

    streamResource.setMIMEType("application/content-stream");
    Page.getCurrent().open(streamResource, null, false);

Hay,

Solution:
Replace “Page.getCurrent().open(streamResource, null, false);” with
“Page.getCurrent().open(streamResource, “_blank”, false);”

Reason:
The documentation for
Page.open(Resource, String, boolean)
leads you to
LegacyWindow.open(Resource, String, boolean)
where it clearly states that:

“”, null and “_self” as windowName all causes the resource to be opened in the current window, replacing any old contents.

AND

“_blank” as windowName causes the resource to always be opened in a new window or tab (depends on the browser and browser settings).

Hope this helps.

By the way: “Thank you in advance.” would be appropriate,
“Expecting help on this.” is not.

Hi,

you have to set “_blank” as windowName (like Tom Keller said) and you have to set the mime-type to application/octet-stream and not to content-stream. application/content-stream doesn´t exist.