commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Cooper <mart...@apache.org>
Subject Re: parsing the file name from the FileUpload bean, so that it works when the client is Windows or unix/linux
Date Mon, 31 May 2004 03:39:09 GMT
On Sun, 16 May 2004, Ben Bookey wrote:

> Dear list,
>
> I am relatively new to Java, so be kind !! I have code which uses the
> Commons.fileupload bean. We are using Tomcat on a linux server, and
> uploading a graphic file, which is then saved into an oracle database. The
> file is stored in a temp directory, before being written to the DB.
>
> When the browser-client is windows which is uploading, the file is saved on
> the Linux server using "c:\test\sample.jpg" as the file name [ results in
> something like i.e. opt/jarkarta/webapps/myapp/tmp/c:\test\sample.jpg ], and
> not sample.jpg which would be correct. This leads to real problems.
>
> The problem is probably the parsing of the string sent as a form item. So

The FileUpload component does not parse the file name. It provides to its
client exactly what the browser provides to it. Unfortunately, different
browsers behave differently - some provide the full path, while others
provide only the file name. If you want to use the same file name on the
server that the client provided (not recommended, for security reasons
amongst others), you'll need to parse out the base file name when the
browser provides the path as well.

--
Martin Cooper


> when I call the item.getName and output to a command window, I only
> get c:\test\sample.jpg.
>
>
>   String fileName = item.getName();
>
>   java.io.File file = new File(fileName);
>   onlyFileName = file.getName();
>
>   System.out.println("Stripped down Filename = " + onlyFileName);
> 		// outputs --> c:\test\sample.jpg
>
>
> I am using then the java File object to parse this file, and I guess it
> needs c:\\test\\sample.jpg for it to work (on linux), which if the command
> window is not lying is giving me just single backslashes. I am not sure if
> the interpreter will automatically replace (behind the scenes) the \ slash
> with \\ without us knowing.
>
> I am not sure if I should now begin to use String replace methods and
> replace a single \ occurence with \\ or something else, when the client is
> windows (determined by using the jsp getHeader()) method.
>
>
> Would really appreciate any advice on this rather confusing subject.
>
> regards
>
> Ben
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message