|
|
@@ -0,0 +1,35 @@
|
|
|
+package com.middle.platform.system.biz.controller;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.middle.platform.common.core.exception.BusinessException;
|
|
|
+import com.middle.platform.common.core.utils.Result;
|
|
|
+import com.middle.platform.oss.config.AliyunOss;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author xucaiqin
|
|
|
+ * @date 2023-12-15 08:46:49
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/file")
|
|
|
+public class FileController {
|
|
|
+ @Resource
|
|
|
+ private AliyunOss aliyunOss;
|
|
|
+
|
|
|
+ @PostMapping("/upload")
|
|
|
+ public Result<Object> upload(@RequestParam("file") MultipartFile file) {
|
|
|
+ if (Objects.isNull(file)) {
|
|
|
+ throw new BusinessException("文件不能为空");
|
|
|
+ }
|
|
|
+ String key = DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd") + "/" + file.getOriginalFilename();
|
|
|
+ return Result.ok(aliyunOss.upload(key, file));
|
|
|
+ }
|
|
|
+}
|