|
@@ -44,6 +44,22 @@ public class FileUploadUtil {
|
|
|
throw new IOException(e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 根据文件路径上传
|
|
|
+ *
|
|
|
+ * @param baseDir 相对应用的基目录
|
|
|
+ * @param file 上传的文件
|
|
|
+ * @return 文件名称
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public static final String uploadWeb2(String baseDir, MultipartFile file) throws IOException {
|
|
|
+ try {
|
|
|
+ return uploadForOrginalFilename(baseDir, file, MimeType.DEFAULT_ALLOWED_EXTENSION);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new IOException(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取文件名的后缀
|
|
@@ -159,4 +175,29 @@ public class FileUploadUtil {
|
|
|
String pathFileName = getPathFileName(baseDir, fileName);
|
|
|
return pathFileName;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 文件上传
|
|
|
+ *
|
|
|
+ * @param baseDir 相对应用的基目录
|
|
|
+ * @param file 上传的文件
|
|
|
+ * @return 返回上传成功的文件名
|
|
|
+ * @throws IOException 比如读写文件出错时
|
|
|
+ */
|
|
|
+ public static final String uploadForOrginalFilename(String baseDir, MultipartFile file, String[] allowedExtension) throws RxcException, IOException, InvalidExtensionException {
|
|
|
+ int fileNamelength = file.getOriginalFilename().length();
|
|
|
+ if (fileNamelength > FileUploadUtil.DEFAULT_FILE_NAME_LENGTH) {
|
|
|
+ throw new RxcException("10004", "文件太大");
|
|
|
+ }
|
|
|
+
|
|
|
+ assertAllowed(file, allowedExtension);
|
|
|
+
|
|
|
+ String fileName = file.getOriginalFilename();//extractFilename(file);
|
|
|
+
|
|
|
+ File desc = getAbsoluteFile(baseDir, fileName);
|
|
|
+ file.transferTo(desc);
|
|
|
+ String pathFileName = getPathFileName(baseDir, fileName);
|
|
|
+ return pathFileName;
|
|
|
+ }
|
|
|
}
|