Commit e3589eae11e00ab530d0ea8eb6bd1fe8d8b367f9

Authored by JeromeSoar
1 parent e4ca2e25

简单上传文件

yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java
1 1 package cn.iocoder.yudao.module.infra.controller.admin.file;
2 2  
  3 +import cn.hutool.core.date.DateUtil;
3 4 import cn.hutool.core.io.IoUtil;
4 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
... ... @@ -23,6 +24,7 @@ import org.springframework.web.multipart.MultipartFile;
23 24 import javax.annotation.Resource;
24 25 import javax.servlet.http.HttpServletResponse;
25 26 import javax.validation.Valid;
  27 +import java.util.Date;
26 28  
27 29 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
28 30  
... ... @@ -47,6 +49,16 @@ public class FileController {
47 49 return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream())));
48 50 }
49 51  
  52 + @PostMapping("/simple-upload")
  53 + @ApiOperation("简单上传文件")
  54 + @ApiImplicitParams({
  55 + @ApiImplicitParam(name = "file", value = "文件附件", required = true, dataTypeClass = MultipartFile.class),
  56 + })
  57 + public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file) throws Exception {
  58 + String path = DateUtil.format(new Date(), "yyyy/MM/dd/") + file.getName();
  59 + return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream())));
  60 + }
  61 +
50 62 @DeleteMapping("/delete")
51 63 @ApiOperation("删除文件")
52 64 @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
... ...