Uploading Files to jsp

Hi,

My app requires the user to upload three different files. I'm using the "file" input type for the first time, but it's not doing what I'd hoped it would. I really just need the absolute path (the path that shows up in the textbox after they select their file) to that file.

I.e.

If they select their file "myFile.txt" in their directory "C:\dir\subdir\myFile.txt", "C:\dir\subdir\myFile.txt" shows up in the text field, but when I call a request.getParameter("fileName") on it, I just get the string "myFile.txt". Is there anyway to get the absolute path?

Message was edited by:

eur0dad

[632 byte] By [eur0dada] at [2007-11-27 11:00:00]
# 1

Not that I am aware of.

In any case it would be almost completely irrelevant as it refers to a location on the client's computer. Because the code is running on the server you can't access in that file directly in any way shape or form.

evnafetsa at 2007-7-29 12:26:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Probably you can use JavaScript to get the actual path of the file

Cheers

Ranjith

ranjith98a at 2007-7-29 12:26:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

You can't. And it is indeed completely irrelevant. Why do you need it?

BalusCa at 2007-7-29 12:26:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Really? My code, like most others, I suppose, uses strings as the file names for which it needs opened. Normally, if I run this as straight java, I would need the absolute file path. What exactly happens when I use a "file" input type to select their files, and how would I use these parameters?

eur0dada at 2007-7-29 12:26:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Oh, I get it now. Thanks!

eur0dada at 2007-7-29 12:26:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

The server can't browse the client's filesystem. That would be a big security hole.

During uploading of files, the client simply selects the file and the form should send the complete file contents along with the filename (and thus not the path) to the server. All you need to do is to store the file contents in a bytearray or an inputstream.

Instead of reinventing the wheel and wasting the time with your unawareness (writing a multipart filter requires basic knowledge how HTTP multipart requests work and as far I read your questions, I don't think that you understand the HTTP specs), you could take a look for existing file upload API's. The Apache commons FileUpload is a nice one.

http://jakarta.apache.org/commons/fileupload/

BalusCa at 2007-7-29 12:26:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...