提交 39e45c1a 作者: 方治民

feat: 优化文件上传 handle

上级 ae13e28e
...@@ -59,16 +59,12 @@ public class UploadProcessServiceImpl implements UploadProcessService { ...@@ -59,16 +59,12 @@ public class UploadProcessServiceImpl implements UploadProcessService {
// Image: 在文件名上追加图片物理像素 // Image: 在文件名上追加图片物理像素
if (isSupportiveImage(suffix)) { if (isSupportiveImage(suffix)) {
@Cleanup object = handleImage(object, file);
InputStream is = file.getInputStream();
object = handleImage(object, is);
} }
// PDF: 在文件名上追加页数,同时在同目录生成 PDF 每一页的图片 // PDF: 在文件名上追加页数,同时在同目录生成 PDF 每一页的图片
if (isPdf(suffix)) { if (isPdf(suffix)) {
@Cleanup object = handlePdf(object, file);
InputStream is = file.getInputStream();
object = handlePdf(object, is);
} }
// Video/Audio: 在文件名上追加时长,视频生成封面图 // Video/Audio: 在文件名上追加时长,视频生成封面图
...@@ -80,13 +76,17 @@ public class UploadProcessServiceImpl implements UploadProcessService { ...@@ -80,13 +76,17 @@ public class UploadProcessServiceImpl implements UploadProcessService {
} }
@SneakyThrows @SneakyThrows
public String handleImage(String object, InputStream is) { public String handleImage(String object, MultipartFile file) {
@Cleanup
InputStream is = file.getInputStream();
BufferedImage image = ImageIO.read(is); BufferedImage image = ImageIO.read(is);
return fillSuffix(object, image.getWidth() + "x" + image.getHeight()); return fillSuffix(object, image.getWidth() + "x" + image.getHeight());
} }
@SneakyThrows @SneakyThrows
public String handlePdf(String object, InputStream is) { public String handlePdf(String object, MultipartFile file) {
@Cleanup
InputStream is = file.getInputStream();
@Cleanup @Cleanup
PDDocument doc = PDDocument.load(is); PDDocument doc = PDDocument.load(is);
int pages = doc.getNumberOfPages(); int pages = doc.getNumberOfPages();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论