Reputation: 753
I have a written a Servlet for uploading the file. On the UI, I want to display a progress bar for the file upload in GWT. How to get file upload speed?
Upvotes: 0
Views: 514
Reputation: 64561
The only way to do it without relying on some server-side helper with "server push" is to send the form or file using XMLHttpRequest
and using its progress events (supported basically everywhere but IE, so you'd need to fallback to a basic form in IE). To do that with GWT, you have to use JSNI though.
If you absolutely need to support IE (and by that I mean display upload progress, because you could easily degrade gracefully to a standard form upload), you'd need the server to tell the client about the progress; that means you need a back-channel with "server push". The easiest is to use GWTUpload then or some similar third-party library.
For display, you can use a <progress>
element. In GWT, the easiest is to use it through UiBinder within an HTMLPanel
: bind it to an Element
@UiField
and modify its properties with setPropertyDouble
et al. It's relatively easy to create a Widget
around a progress element created through Document.get().createElement("progress")
. Or you can use a third-party library (GWT-Bootstrap or else) or create a progress bar out of <div>
elements and CSS. Again, it depends which browsers you want/need to support.
Upvotes: 3