简单上传文件

pull/2/head
JeromeSoar 2022-04-24 17:55:16 +08:00
parent e4ca2e25f9
commit e3589eae11
1 changed files with 12 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.infra.controller.admin.file; package cn.iocoder.yudao.module.infra.controller.admin.file;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -23,6 +24,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.Date;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -47,6 +49,16 @@ public class FileController {
return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream()))); return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream())));
} }
@PostMapping("/simple-upload")
@ApiOperation("简单上传文件")
@ApiImplicitParams({
@ApiImplicitParam(name = "file", value = "文件附件", required = true, dataTypeClass = MultipartFile.class),
})
public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file) throws Exception {
String path = DateUtil.format(new Date(), "yyyy/MM/dd/") + file.getName();
return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream())));
}
@DeleteMapping("/delete") @DeleteMapping("/delete")
@ApiOperation("删除文件") @ApiOperation("删除文件")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)