GWT 1.4: Getting file path for FileUpload?

1,855 views
Skip to first unread message

zilvonias

unread,
Dec 29, 2008, 10:52:02 AM12/29/08
to Google Web Toolkit
Hi all!

Is there a way, client-side, to fetch the filepath for a FileUpload
widget, i.e.

1. User selects a file using the FileUpload widget.
2. GWT client requests the filename and filepath of the file selected
from the FileUpload widget.

I'm currently using GWT 1.4.61. Thanks!

Kevin Tarn

unread,
Dec 29, 2008, 12:06:51 PM12/29/08
to Google-We...@googlegroups.com
There is no way to get file path from client side due to browser's security policy. You have to do it via a signed java applet or get it from your servlet.

Kevin

Lothar Kimmeringer

unread,
Dec 29, 2008, 12:12:17 PM12/29/08
to Google-We...@googlegroups.com
zilvonias schrieb:

> 1. User selects a file using the FileUpload widget.
> 2. GWT client requests the filename and filepath of the file selected
> from the FileUpload widget.

fileUpload.getFilename should return the filename including the
absolute path. So you "only" need to separate the two parts
using indexOf and substring.


Regards, Lothar

Kevin Tarn

unread,
Dec 29, 2008, 12:28:49 PM12/29/08
to Google-We...@googlegroups.com
You cannot rely on getFilename to return full path of file. It depens on browser. For example, Firefox did not return full path of it.

Kevin

Lothar Kimmeringer

unread,
Dec 29, 2008, 1:10:04 PM12/29/08
to Google-We...@googlegroups.com
Kevin Tarn schrieb:

> You cannot rely on getFilename to return full path of file. It depens on
> browser. For example, Firefox did not return full path of it.

Maybe you can achieve something accessing DOM directly. At least
the full path shows up in the text-field of the FileUpload-widget
in Firefox as well.


Regards, Lothar

zilvonias

unread,
Jan 2, 2009, 9:59:14 AM1/2/09
to Google Web Toolkit
I discovered the same as well. Full path with IE, filename only with
Firefox.

zilvonias

unread,
Jan 2, 2009, 10:01:07 AM1/2/09
to Google Web Toolkit
I'll do some experiments and see if I can fetch it from the DOM.

The use case is that the user is attempting to store the filepath of a
chosen file. I thought it'd be nice to have the user use the
FileUpload to choose the file instead of manually typing the file
path. If there's another way to create a file-browsing widget and get
the file path that way, I'd consider it.

On Dec 29 2008, 1:10 pm, Lothar Kimmeringer <j...@kimmeringer.de>
wrote:

El Mentecato Mayor

unread,
Jan 2, 2009, 3:02:44 PM1/2/09
to Google Web Toolkit
AFAIK, there's no way to do what you want with just JavaScript.
We achieve what you described with a Java Applet, saving the preferred
path on the server for each user. Of course it has the overload and
drawbacks of an applet (heavier, JRE plugin required, etc), but on the
plus side we support multiple-file uploads (including entire
directories), drag-n-drop, and uploading very large files by breaking
them into chunks.
Reply all
Reply to author
Forward
0 new messages