|
@@ -1,8 +1,10 @@
|
|
|
package cn.iocoder.yudao.module.infra.controller.admin.file;
|
|
package cn.iocoder.yudao.module.infra.controller.admin.file;
|
|
|
|
|
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.core.util.URLUtil;
|
|
import cn.hutool.core.util.URLUtil;
|
|
|
|
|
+import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
|
|
|
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;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
@@ -25,6 +27,8 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
|
|
|
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
+
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
import static cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils.writeAttachment;
|
|
import static cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils.writeAttachment;
|
|
|
|
|
|
|
@@ -104,6 +108,9 @@ public class FileController {
|
|
|
@Operation(summary = "上传文件", description = "模式一:后端上传文件;返回的为对象")
|
|
@Operation(summary = "上传文件", description = "模式一:后端上传文件;返回的为对象")
|
|
|
public CommonResult<FileRespVO> uploadFile(FileUploadReqVO uploadReqVO) throws Exception {
|
|
public CommonResult<FileRespVO> uploadFile(FileUploadReqVO uploadReqVO) throws Exception {
|
|
|
MultipartFile file = uploadReqVO.getFile();
|
|
MultipartFile file = uploadReqVO.getFile();
|
|
|
|
|
+ if (file == null) {
|
|
|
|
|
+ CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(), "文件不能为空");
|
|
|
|
|
+ }
|
|
|
String path = uploadReqVO.getPath();
|
|
String path = uploadReqVO.getPath();
|
|
|
return success(fileService.uploadFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())));
|
|
return success(fileService.uploadFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())));
|
|
|
}
|
|
}
|