commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ben Bookey" <>
Subject parsing the file name from the FileUpload bean, so that it works when the client is Windows or unix/linux
Date Sun, 16 May 2004 14:18:54 GMT
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
when I call the item.getName and output to a command window, I only
get c:\test\sample.jpg.

  String fileName = item.getName(); 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.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message