From 8391898b266b2cc02bbe9d9c94b36bddb9d3b73e Mon Sep 17 00:00:00 2001 From: jeromesoar Date: Sun, 24 Apr 2022 22:43:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=89=8D=E7=AB=AF=20ImageUpload=20?= =?UTF-8?q?=E7=BB=84=E4=BB=B6):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 前端 ImageUpload 组件, 上传路径以及地址拼接 - 基础设施-文件上传, 新增简单上传接口 --- .../controller/admin/file/FileController.java | 18 ++++++++++++++++++ .../admin/file/vo/file/SimpleUploadRespVO.java | 16 ++++++++++++++++ .../src/components/ImageUpload/index.vue | 13 +++++++------ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/SimpleUploadRespVO.java diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java index e3d810dec..071c89f43 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java @@ -1,11 +1,14 @@ package cn.iocoder.yudao.module.infra.controller.admin.file; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; +import cn.hutool.core.util.IdUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO; import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileRespVO; +import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.SimpleUploadRespVO; import cn.iocoder.yudao.module.infra.convert.file.FileConvert; import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO; import cn.iocoder.yudao.module.infra.service.file.FileService; @@ -47,6 +50,21 @@ public class FileController { 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 uploadFile(@RequestParam("file") MultipartFile file) throws Exception { + SimpleUploadRespVO simpleUploadRespVO = new SimpleUploadRespVO(); + simpleUploadRespVO.setFileName(file.getOriginalFilename()); + // TODO 日期路径, 随机文件名 + String path = IdUtil.fastSimpleUUID() + "." + FileUtil.extName(file.getOriginalFilename()); + String fileUrl = fileService.createFile(path, IoUtil.readBytes(file.getInputStream())); + simpleUploadRespVO.setFileUrl(fileUrl); + return success(simpleUploadRespVO); + } + @DeleteMapping("/delete") @ApiOperation("删除文件") @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/SimpleUploadRespVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/SimpleUploadRespVO.java new file mode 100644 index 000000000..369d9f578 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/SimpleUploadRespVO.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.infra.controller.admin.file.vo.file; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel(value = "管理后台 - 简单上传文件 VO", description = "简单上传文件, 不需要 path") +public class SimpleUploadRespVO { + + @ApiModelProperty(value = "文件名", required = true, example = "yudao.jpg") + private String fileName; + + @ApiModelProperty(value = "文件 URL", required = true, example = "https://www.iocoder.cn/yudao.jpg") + private String fileUrl; +} diff --git a/yudao-ui-admin/src/components/ImageUpload/index.vue b/yudao-ui-admin/src/components/ImageUpload/index.vue index 170c1bd08..0abe65a6b 100644 --- a/yudao-ui-admin/src/components/ImageUpload/index.vue +++ b/yudao-ui-admin/src/components/ImageUpload/index.vue @@ -43,7 +43,7 @@