I need some help to get my FileUpload servlet to work "cross-platform".
 
It works okay when uploading a file from a Windows machine to a Windows server but it misbehaves when I try to upload a file from a Windows machine to a Linux server; it isn't setting the file name properly.
 
In a Windows->Windows scenario, the file I am uploading is something like C:\original-dir\original-subdir\my.file. My servlet uses lastIndexOf(File.separator) to find the file name proper, e.g. my.file, and then concatenates it to the end of the path where I want the file stored in the server, e.g. C:\stored-dir\stored-subdir\my.file. The servlet saves the file successfully and when I look at the C:\stored-dir\stored-subdir directory in my file system, the file name is my.file, exactly as I want.
 
In a Windows->Linux scenario (i.e. uploading a Windows file to a Linux server), the servlet stores the file in the desired directory but it has its full original name, e.g. C:\original-dir\original-subdir\my.file, not just my.file. That means that the full file name of the uploaded file is something along the lines of /home/rhino/tomcat4/webapps/FileUploadServlet/SDAC-upload/C:\\original-dir\\original-subdir\\my.file. Clearly, that is not desireable; I want the uploaded file name to be /home/rhino/tomcat4/webapps/FileUploadServlet/SDAC-upload/my.file.
 
It seems clear to me that the file separator is the problem here. When the servlet is running in Linux, it determines the value of file.separator to be '/' while the file being uploaded is in Windows which has a file.separator of '\'. The lastIndexOf(File.separator) therefore never finds the file name proper and saves the entire path in the name, not just the last bit.
 
I'm not so sure what to do about it. Do I need to have my code determine the OS from which it is getting the file which is being uploaded or is there some other technique I need to use? How would I determine the OS from which I'm uploading? I know that I can get the OS of the server from the Java system property "os.name" but how do I get the OS which is the source of the file upload?
 
I am running Tomcat 4.1.24 on both the Windows XP and Linux boxes. The Linux box is running Mandrake 9.1.
 

Rhino
---
rhino1 AT sympatico DOT ca
"If you want the best seat in the house, you'll have to move the cat."

Reply via email to