Upload blob: image from GWT

627 views
Skip to first unread message

Xybrek

unread,
Sep 6, 2013, 12:40:06 AM9/6/13
to google-we...@googlegroups.com
I managed to get a blob and create a URL for it which I put in a img tag src attribute to show the image like this:

<img class="gwt-Image" data-field="image" src="blob:http%3A//127.0.0.1%3A8888/757c3c87-de5c-4c54-897e-9d043bc2895c">

My question would be how would I upload this blob via GWT FileUpload with com.google.gwt.user.client.ui.FormPanel?

Also the com.google.gwt.user.client.ui.FileUpload does not have a setFilename method to programatically set the filename as oppose to selecting via File/Window box.

So, it seems its like impossible to do this with GWT, I've seen pure Javascript solution.

Thad Humphries

unread,
Sep 7, 2013, 4:33:10 AM9/7/13
to google-we...@googlegroups.com
For security reasons, <input type="file"... element cannot have a value set programmatically. For an example why not, see http://stackoverflow.com/a/1696884/1316011  (If you have code showing otherwise, I'm sure I'm not the only one who'd like to see it.)

As for uploading a file, the example in the GWT JavaDoc for FileUpload works. Obviously you need a servlet that saves the file. I use Apache Commons FileUpload for my servlets (http://commons.apache.org/proper/commons-fileupload/).

Once you get the file up, you can use a GWT RPC call to open the file, to convert it to a Base64 string, and return it to your browser where you can call Image.setUrl(...your-Base64...). However it would be faster and simpler to write a servlet that streams the image back to you, and call that servlet in Image.setUrl()
Reply all
Reply to author
Forward
0 new messages