提交 39e45c1a 作者: 方治民

feat: 优化文件上传 handle

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