|
|
@@ -1,5 +1,9 @@
|
|
|
package com.xunmei.file.utils;
|
|
|
|
|
|
+import cn.hutool.core.codec.Base64;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.io.file.FileNameUtil;
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
import com.xunmei.common.core.exception.file.FileException;
|
|
|
import com.xunmei.common.core.exception.file.FileNameLengthLimitExceededException;
|
|
|
import com.xunmei.common.core.exception.file.FileSizeLimitExceededException;
|
|
|
@@ -10,6 +14,7 @@ import com.xunmei.common.core.utils.file.FileTypeUtils;
|
|
|
import com.xunmei.common.core.utils.file.MimeTypeUtils;
|
|
|
import com.xunmei.common.core.utils.uuid.Seq;
|
|
|
import com.xunmei.file.controller.SysFileController;
|
|
|
+import com.xunmei.file.vo.FileBase64Vo;
|
|
|
import org.apache.commons.io.FilenameUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -111,6 +116,20 @@ public class FileUploadUtils
|
|
|
return getPathFileName(fileName);
|
|
|
}
|
|
|
|
|
|
+ public static final String uploadBase64(String baseDir, FileBase64Vo file)
|
|
|
+ throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
|
|
|
+ InvalidExtensionException{
|
|
|
+
|
|
|
+ byte[] decode = Base64.decode(file.getContent());
|
|
|
+ String fileName = extractFilename(file.getExtension());
|
|
|
+ File absoluteFile = getAbsoluteFile(baseDir, fileName);
|
|
|
+ FileUtil.writeBytes(decode,absoluteFile);
|
|
|
+ return getPathFileName(fileName);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 编码文件名
|
|
|
*/
|
|
|
@@ -119,7 +138,16 @@ public class FileUploadUtils
|
|
|
return StringUtils.format("{}/{}.{}", DateUtils.datePath(), Seq.getId(Seq.uploadSeqType), FileTypeUtils.getExtension(file));
|
|
|
}
|
|
|
|
|
|
- private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException
|
|
|
+ /**
|
|
|
+ * 编码文件名
|
|
|
+ */
|
|
|
+ public static final String extractFilename(String fileLast)
|
|
|
+ {
|
|
|
+ return StringUtils.format("{}/{}.{}", DateUtils.datePath(), Seq.getId(Seq.uploadSeqType), fileLast);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException
|
|
|
{
|
|
|
File desc = new File(uploadDir + File.separator + fileName);
|
|
|
log.info("当前上传文件地址:{}",desc.getAbsolutePath());
|