Upload Select Component Issue

Hi,

I am using a Echo2 component is UploadSelect to upload a file.
My sever is Tomcat and OS is Fedora8, by Using mozilla based browser (Firefox), I am getting the exact file path ( if it is "/home/gan/software/Testing/image1.jpg", I am getting the file name as "image1.jpg").

If I connect to my application through IE (in Windows machine) its giving me total path as file name ( if it is "C:\Documents and settings\AllUsers\Documents\My Pictures\Sample Pictures\Sunset.jpg", I am getting the file name as "C:\Documents and settings\AllUsers\Documents\My Pictures\Sample Pictures\Sunset.jpg". Actually I required only "Sunset.jpg").

The code is:

*********************************************************************************
objUploadSelect.addUploadListener(new UploadListener() {
public void fileUpload(UploadEvent e) {

e.getFileName();

System.out.println("--------e.getFileName()-------"+e.getFileName()); // here I am getting the total path in IE

}

public void invalidFileUpload(UploadEvent e) {

}

});

*********************************************************************************

Thanks in advance

Regards
-Gan

a.schild's picture

Yes, it's the way IE works

I think best is to look if you see any \ in the filename.
If yes, then only take the part behind the last \.

André

This is because IE sends the

This is because IE sends the whole path, which is fine according to the spec (?). See http://commons.apache.org/fileupload/faq.html#whole-path-from-IE for a workaround.

Is there any alternative

But, I think this is not the correct way.

Because, in my fedora machine I uploaded a file which contains "\" in it's name (Eg: "Test\document.doc") then I will get the last name only no (like "document.doc").

Is there any alternative to avoid same.

-Thanks & Regards
Gan

a.schild's picture

I'm not sure what the the

I'm not sure what the the FilenameUtils.getName(filename); from jakarta does, but I myself would implement something like:

- Check if the filename starts with \\ -> IE specific code, take part after last \
- Check if the filename has a : at the second position (handle case when filename is only 1 char length) -> IE specific code
- Otherwise use the whole string as filename

I think even when you can upload files with \ characters in the name from linux there are some dangers in this.
Some parts of the code, sql engine, rendering engine etc. might well interpret this as a "escape" character...

André

Agree, slashes in file names

Agree, slashes in file names is asking for trouble. You could keep the code IE-only, customers will never run into issues with slashes in file names, since Windows does not allow them.

Niels