Normalize upload file names by cutting off any path info before the actual file name.
This commit is contained in:
parent
9b97203b3a
commit
7e44b71d6d
1 changed files with 17 additions and 1 deletions
|
@ -39,7 +39,7 @@ public class MimePart implements Serializable {
|
|||
* @param contentType ...
|
||||
*/
|
||||
public MimePart(String name, byte[] content, String contentType) {
|
||||
this.name = name;
|
||||
this.name = normalizeFilename(name);
|
||||
this.content = (content == null) ? new byte[0] : content;
|
||||
this.contentType = contentType;
|
||||
contentLength = (content == null) ? 0 : content.length;
|
||||
|
@ -189,4 +189,20 @@ public class MimePart implements Serializable {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a upload file name. Internet Explorer on Windows sends
|
||||
* the whole path, so we cut off everything before the actual name.
|
||||
*/
|
||||
public static String normalizeFilename(String filename) {
|
||||
if (filename == null)
|
||||
return null;
|
||||
int idx = filename.lastIndexOf('/');
|
||||
if (idx > -1)
|
||||
filename = filename.substring(idx + 1);
|
||||
idx = filename.lastIndexOf('\\');
|
||||
if (idx > -1)
|
||||
filename = filename.substring(idx + 1);
|
||||
return filename;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue