How to upload image from file system and add it to RootPanel

45 views
Skip to first unread message

mablaev

unread,
Apr 28, 2008, 8:50:39 AM4/28/08
to Google Web Toolkit
Hi all, I'm novice at GWT and have such question: Can I choose a image
file from file system by using file open dialog and add it to
RootPanel as Image widget?

Thanks....

Michael D'Amour

unread,
Apr 28, 2008, 4:38:48 PM4/28/08
to Google Web Toolkit

Yeah, I have some code that does something like this. My fileupload
POST url is actually a PHP page which sends back to the GWT client an
XML response which is parsed to give me back the filename (URL) on the
server (the images have a unique GUID attached upon upload). With the
XML response, I can build an Image with the URL and do anything with
it...

-Mike

sal...@gmail.com

unread,
Apr 29, 2008, 9:45:40 AM4/29/08
to Google Web Toolkit
The image has to be stored on the server hosting your GWT app. I don't
think browser security policies allow a page that hosted directly on
the user's system to access files on the system.

For instance, www.foo.com cannot reference c:\pictures\DSCF001.jpg .
The user would have to upload DSCF001.jpg to www.foo.com, after which
foo.com will create an Image widget from it.

On Apr 28, 8:50 am, mablaev <Marlen.Abl...@gmail.com> wrote:

Thomas Broyer

unread,
Apr 29, 2008, 5:50:36 AM4/29/08
to Google Web Toolkit
If you don't want a true "upload" (for whatever reason) or want the
image to show before or during the upload ("preview"), try doing a new
Image(myFileUpload.getFilename()).

Note that it won't work on some browsers (Opera at least), on which
getFilename() returns only the file name, without the path.

As for Michael's answer, I'd rather return JSON than XML (far easier
and lightweight to parse), or even just the image URI as "text/uri-
list" (see section 5 of http://www.ietf.org/rfc/rfc2483.txt) or "text/
plain"

MonkeyMike

unread,
Jun 25, 2008, 6:12:58 PM6/25/08
to Google Web Toolkit
> If you don't want a true "upload" (for whatever reason) or want the
> image to show before or during the upload ("preview"), try doing a new
> Image(myFileUpload.getFilename()).

This did not work for me, so beware to those who try it.
Reply all
Reply to author
Forward
0 new messages