正在显示
3 个修改的文件
包含
24 行增加
和
2 行删除
| @@ -68,4 +68,14 @@ public class InvalidExtensionException extends FileUploadException | @@ -68,4 +68,14 @@ public class InvalidExtensionException extends FileUploadException | ||
| 68 | super(allowedExtension, extension, filename); | 68 | super(allowedExtension, extension, filename); |
| 69 | } | 69 | } |
| 70 | } | 70 | } |
| 71 | + | ||
| 72 | + public static class InvalidVideoExtensionException extends InvalidExtensionException | ||
| 73 | + { | ||
| 74 | + private static final long serialVersionUID = 1L; | ||
| 75 | + | ||
| 76 | + public InvalidVideoExtensionException(String[] allowedExtension, String extension, String filename) | ||
| 77 | + { | ||
| 78 | + super(allowedExtension, extension, filename); | ||
| 79 | + } | ||
| 80 | + } | ||
| 71 | } | 81 | } |
| @@ -130,8 +130,11 @@ public class FileUploadUtils | @@ -130,8 +130,11 @@ public class FileUploadUtils | ||
| 130 | private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException | 130 | private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException |
| 131 | { | 131 | { |
| 132 | File desc = new File(uploadDir + File.separator + fileName); | 132 | File desc = new File(uploadDir + File.separator + fileName); |
| 133 | - if (!desc.exists()) { | ||
| 134 | - if (!desc.getParentFile().exists()) { | 133 | + |
| 134 | + if (!desc.exists()) | ||
| 135 | + { | ||
| 136 | + if (!desc.getParentFile().exists()) | ||
| 137 | + { | ||
| 135 | desc.getParentFile().mkdirs(); | 138 | desc.getParentFile().mkdirs(); |
| 136 | } | 139 | } |
| 137 | } | 140 | } |
| @@ -182,6 +185,11 @@ public class FileUploadUtils | @@ -182,6 +185,11 @@ public class FileUploadUtils | ||
| 182 | throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension, | 185 | throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension, |
| 183 | fileName); | 186 | fileName); |
| 184 | } | 187 | } |
| 188 | + else if (allowedExtension == MimeTypeUtils.VIDEO_EXTENSION) | ||
| 189 | + { | ||
| 190 | + throw new InvalidExtensionException.InvalidVideoExtensionException(allowedExtension, extension, | ||
| 191 | + fileName); | ||
| 192 | + } | ||
| 185 | else | 193 | else |
| 186 | { | 194 | { |
| 187 | throw new InvalidExtensionException(allowedExtension, extension, fileName); | 195 | throw new InvalidExtensionException(allowedExtension, extension, fileName); |
| @@ -24,6 +24,8 @@ public class MimeTypeUtils | @@ -24,6 +24,8 @@ public class MimeTypeUtils | ||
| 24 | public static final String[] MEDIA_EXTENSION = { "swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg", | 24 | public static final String[] MEDIA_EXTENSION = { "swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg", |
| 25 | "asf", "rm", "rmvb" }; | 25 | "asf", "rm", "rmvb" }; |
| 26 | 26 | ||
| 27 | + public static final String[] VIDEO_EXTENSION = { "mp4", "avi", "rmvb" }; | ||
| 28 | + | ||
| 27 | public static final String[] DEFAULT_ALLOWED_EXTENSION = { | 29 | public static final String[] DEFAULT_ALLOWED_EXTENSION = { |
| 28 | // 图片 | 30 | // 图片 |
| 29 | "bmp", "gif", "jpg", "jpeg", "png", | 31 | "bmp", "gif", "jpg", "jpeg", "png", |
| @@ -31,6 +33,8 @@ public class MimeTypeUtils | @@ -31,6 +33,8 @@ public class MimeTypeUtils | ||
| 31 | "doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt", | 33 | "doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt", |
| 32 | // 压缩文件 | 34 | // 压缩文件 |
| 33 | "rar", "zip", "gz", "bz2", | 35 | "rar", "zip", "gz", "bz2", |
| 36 | + // 视频格式 | ||
| 37 | + "mp4", "avi", "rmvb", | ||
| 34 | 38 | ||
| 35 | "pdf" }; | 39 | "pdf" }; |
| 36 | 40 |
-
请 注册 或 登录 后发表评论