| | |
| | | package com.vci.ubcs.resource.endpoint; |
| | | |
| | | import com.vci.ubcs.resource.entity.Attach; |
| | | import com.vci.ubcs.common.validator.ComprehensiveFileValidator; |
| | | import io.swagger.annotations.Api; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | /** |
| | | * 对象存储端点 |
| | |
| | | */ |
| | | private final IAttachService attachService; |
| | | |
| | | /** |
| | | * 文件安全检查 |
| | | */ |
| | | @Autowired |
| | | private ComprehensiveFileValidator fileValidator; |
| | | |
| | | /** |
| | | * 创建存储桶 |
| | |
| | | @SneakyThrows |
| | | @PostMapping("/put-file") |
| | | public R<BladeFile> putFile(@RequestParam MultipartFile file) { |
| | | // 使用文件安全验证器 |
| | | ComprehensiveFileValidator.UploadValidationResult result = fileValidator.validateFile(file); |
| | | if (!result.isValid()) { |
| | | return R.fail(result.getMessage()); |
| | | } |
| | | BladeFile bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(), file.getInputStream()); |
| | | return R.data(bladeFile); |
| | | } |
| | |
| | | @SneakyThrows |
| | | @PostMapping("/put-file-by-name") |
| | | public R<BladeFile> putFile(@RequestParam String fileName, @RequestParam MultipartFile file) { |
| | | // 使用文件安全验证器 |
| | | ComprehensiveFileValidator.UploadValidationResult result = fileValidator.validateFile(file); |
| | | if (!result.isValid()) { |
| | | return R.fail(result.getMessage()); |
| | | } |
| | | BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream()); |
| | | return R.data(bladeFile); |
| | | } |
| | | |
| | | // /** |
| | | // * 上传文件并保存至附件表 |
| | | // * |
| | | // * @param file 文件 |
| | | // * @return ObjectStat |
| | | // */ |
| | | // @SneakyThrows |
| | | // @PostMapping("/put-file-attach") |
| | | // public R<BladeFile> putFileAttach(@RequestParam MultipartFile file) { |
| | | // String fileName = file.getOriginalFilename(); |
| | | // BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream()); |
| | | // Long attachId = buildAttach(fileName, file.getSize(), bladeFile); |
| | | // bladeFile.setAttachId(attachId); |
| | | // return R.data(bladeFile); |
| | | // } |
| | | |
| | | // /** |
| | | // * 上传文件并保存至附件表 |
| | | // * |
| | | // * @param fileName 存储桶对象名称 |
| | | // * @param file 文件 |
| | | // * @return ObjectStat |
| | | // */ |
| | | // @SneakyThrows |
| | | // @PostMapping("/put-file-attach-by-name") |
| | | // public R<BladeFile> putFileAttach(@RequestParam String fileName, @RequestParam MultipartFile file) { |
| | | // BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream()); |
| | | // Long attachId = buildAttach(fileName, file.getSize(), bladeFile); |
| | | // bladeFile.setAttachId(attachId); |
| | | // return R.data(bladeFile); |
| | | // } |
| | | |
| | | /** |
| | | * 构建附件表 |