views:

201

answers:

2

I want full path of selected file using GWT by using FileUpload. Can you help me?

+3  A: 

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.

fileUpload.getFilename may or may not return full path. Depends on the browser

Sorantis
is there any way to do this ?
Tushar Ahirrao
+1  A: 

You don't need it. Imagine that I am the client and you are the server. I give you the full file path "C:/My Documents/passwords.txt", how would you as being the server ever programmatically access the content of the file? With new File("C:/My Documents/passwords.txt") maybe? No, think logically about it, this ain't going to work as we both runs at physically different machines. The information about the full path is worthless.

The HTML file upload actually sends the content of the file from the client to the server, usually along with only the file name. You just need to grab the content as an InputStream by FileItem#getInputStream() or just to write it to disk directly by FileItem#write(). as per the FileUpload User Guide.

You can get the sole filename by FileItem#getName(), but some webbrowsers however sends the full client side disk file system path, such as Internet Explorer and Opera. This is wrong. You need to trim off the path by FilenameUtils#getName() as per the FileUpload FAQ.

(by the way, all code in blue is clickable and points to the Javadocs, I strongly recommend you to learn reading/interpreting it as well, they namely provide all information you need).

BalusC
Also, IMO: If a browser sends that information, it's somehow abusing the user's trust: Do I really want to disclose my username, or the way I organize my files (which is all in my paths)? For me, that's one more nail in the coffin for IE (and unfortunately, also Opera as I've just learned).
Chris Lercher