StreamResource download issues

Hello,

just asking, has anyone managed to figure out a
semi decent way
of serving StreamResources from Vaadin app?

For example, it is painfull to deal with extremely common situation of downloading ZIP/DOC/JPG/etc content from a web page using pure Vaadin infrastructure. See the explanation below.


Use-case 1:

ContentMode:
inline

Code: getApplication().getMainWindow().open(resource,
“_blank”
);

Result:
a) Some browsers open the content in a brand new browser window instead in a new tab. That’s rather unprofessional and confusing.
b) Some browsers in default configuration will refuse to open window due to popup blocker functionality, at that point either nothing happens or user gets prompted to enable popup. The latter implies forced page refresh → restart of Vaadin application. Unusable.


Use-case 2:

ContentMode:
attachment

Code: getApplication().getMainWindow().open(resource);

Result:
a) Looks and works good at a first glance. However it’s not reliable enough for normal use, plus not recommended way as noted in Window.open javadoc.
b) Client tends to go out of sync when streaming occures. Red notification: Connection failure, Invalid status code 0 (server down?). That’s 100% reproducible on Chrome / Chromium. Harder to reproduce on FF / IE.
c) It also seems to matter how the download action was initiated by user. In particular - the failure rate is different for click on Button and click on Embedded. Embedded being the worse.


Use-case 3:

ContentMode:
attachment

Code: getApplication().getMainWindow().open(resource,
“_blank”
);

Result:
a) Similar to use-case 1.
b) New window appears for a split of second to be replaced by save/open requester. Under some circumstances (browser / mimetype combo) even no save/open dialog comes up.

So either i am missing a piece of puzzle or such scenarios is really difficult or impossible to cover using pure Vaadin approach. If the latter was true, transition to old good servlet download handlers would be the only option, sadly.

I would be thankful for some tips :smug:

Hi,

I had the same problem, and this link helps me to get what I expect.


http://code.google.com/p/aperte-reports/source/browse/aperte-reports-ui/src/main/java/org/apertereports/util/FileStreamer.java

12335.java (2.82 KB)