|
@@ -1,13 +1,10 @@
|
|
|
package com.chelvc.cloud.maintain.controller;
|
|
|
|
|
|
-import java.awt.image.BufferedImage;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
-import java.util.Objects;
|
|
|
-import javax.imageio.ImageIO;
|
|
|
|
|
|
import com.chelvc.framework.base.annotation.UnifiedResponseBody;
|
|
|
-import com.chelvc.framework.base.util.ErrorUtils;
|
|
|
+import com.chelvc.framework.base.util.FileUtils;
|
|
|
import com.chelvc.framework.upload.UploadHandler;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -31,19 +28,17 @@ public class FileController {
|
|
|
private final UploadHandler uploadHandler;
|
|
|
|
|
|
/**
|
|
|
- * 上传图片
|
|
|
+ * 上传文件
|
|
|
*
|
|
|
- * @param file 图片文件
|
|
|
- * @return 图片地址
|
|
|
+ * @param file 文件对象
|
|
|
+ * @return 文件地址
|
|
|
* @throws IOException I/O异常
|
|
|
*/
|
|
|
- @PostMapping("/file/image")
|
|
|
- public String uploadImage(@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
- BufferedImage image;
|
|
|
- try (InputStream input = file.getInputStream()) {
|
|
|
- image = ImageIO.read(input);
|
|
|
+ @PostMapping("/file")
|
|
|
+ public String upload(@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
+ String suffix = FileUtils.getSuffix(file.getName());
|
|
|
+ try (InputStream stream = file.getInputStream()) {
|
|
|
+ return this.uploadHandler.upload(stream, suffix);
|
|
|
}
|
|
|
- ErrorUtils.availableResource(Objects.nonNull(image), "图片上传失败");
|
|
|
- return this.uploadHandler.upload(image);
|
|
|
}
|
|
|
}
|