| | |
| | | import org.sxkj.resource.util.ImageCompressorUtil; |
| | | import springfox.documentation.annotations.ApiIgnore; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | @PostMapping("/put-file") |
| | | @ApiOperation(value = "上传文件", notes = "上传文件") |
| | | public R<BladeFile> putFile(@RequestParam MultipartFile file) { |
| | | BladeFile bladeFile = ossBuilder.template("estack").putFile(file.getOriginalFilename(), file.getInputStream()); |
| | | // 步骤1: 将文件转换为字节数组,避免流重置异常 |
| | | byte[] bytes = file.getBytes(); |
| | | // 步骤2: 使用字节数组输入流上传文件 |
| | | BladeFile bladeFile = ossBuilder.template("estack").putFile(file.getOriginalFilename(), new ByteArrayInputStream(bytes)); |
| | | return R.data(bladeFile); |
| | | } |
| | | |
| | |
| | | @PostMapping("/put-file-by-name") |
| | | @ApiOperation(value = "上传文件", notes = "上传文件-存储桶对象名称") |
| | | public R<BladeFile> putFile(@RequestParam String fileName, @RequestParam MultipartFile file) { |
| | | BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream()); |
| | | // 步骤1: 将文件转换为字节数组,避免流重置异常 |
| | | byte[] bytes = file.getBytes(); |
| | | // 步骤2: 使用字节数组输入流上传文件 |
| | | BladeFile bladeFile = ossBuilder.template().putFile(fileName, new ByteArrayInputStream(bytes)); |
| | | return R.data(bladeFile); |
| | | } |
| | | |
| | |
| | | public R<BladeFile> putFileAttach(@RequestParam String fileName, |
| | | @RequestParam List<List<String>> resultType, |
| | | @RequestParam MultipartFile file) { |
| | | BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream()); |
| | | // 步骤1: 将文件转换为字节数组,避免流重置异常 |
| | | byte[] bytes = file.getBytes(); |
| | | // 步骤2: 使用字节数组输入流上传文件 |
| | | BladeFile bladeFile = ossBuilder.template().putFile(fileName, new ByteArrayInputStream(bytes)); |
| | | Long attachId = buildAttach(fileName, resultType, file.getSize(), bladeFile); |
| | | bladeFile.setAttachId(attachId); |
| | | return R.data(bladeFile); |
| | |
| | | |
| | | @NotNull |
| | | private BladeFile getBladeFile(@RequestParam MultipartFile file) throws IOException { |
| | | // 步骤1: 获取文件名 |
| | | String fileName = file.getOriginalFilename(); |
| | | BladeFile bladeFile = ossBuilder.template("estack").putFile(fileName, file.getInputStream()); |
| | | // 步骤2: 将文件转换为字节数组,避免流重置异常 |
| | | byte[] bytes = file.getBytes(); |
| | | // 步骤3: 使用字节数组输入流上传文件 |
| | | BladeFile bladeFile = ossBuilder.template("estack").putFile(fileName, new ByteArrayInputStream(bytes)); |
| | | // 步骤4: 构建附件信息 |
| | | Long attachId = buildAttach(fileName, null, file.getSize(), bladeFile); |
| | | bladeFile.setAttachId(attachId); |
| | | return bladeFile; |