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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to