feat(upload): 修改大文件上传合并接口
- 将合并接口返回类型从 AjaxResult 更改为 R<Map<String, String>> - 使用 Map 结构封装文件 URL、原始文件名和 OSS ID - 统一异常处理,失败时返回 R.fail 包装的错误信息 - 添加 ossId 转换为字符串类型的处理逻辑 - 引入 R 类和相关工具类支持新的返回结构
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
package com.ruoyi.web.controller.common;
|
||||
|
||||
import com.ruoyi.common.core.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.domain.vo.SysOssVo;
|
||||
import com.ruoyi.web.service.ChunkedUploadService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.redisson.api.RMap;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Validated
|
||||
@RestController
|
||||
@@ -53,17 +57,18 @@ public class BigUploadController {
|
||||
* @return 合并结果及文件信息
|
||||
*/
|
||||
@PostMapping("/merge")
|
||||
public AjaxResult merge(@RequestParam("fileMd5") String fileMd5,
|
||||
@RequestParam("fileName") String fileName,
|
||||
@RequestParam("totalChunks") int totalChunks) {
|
||||
public R<Map<String, String>> merge(@RequestParam("fileMd5") String fileMd5,
|
||||
@RequestParam("fileName") String fileName,
|
||||
@RequestParam("totalChunks") int totalChunks) {
|
||||
try {
|
||||
SysOssVo oss = chunkedUploadService.mergeChunks(fileMd5, fileName, totalChunks);
|
||||
return AjaxResult.success()
|
||||
.put("url", oss.getUrl())
|
||||
.put("fileName", oss.getOriginalName())
|
||||
.put("ossId", oss.getOssId());
|
||||
Map<String, String> map = new HashMap<>(2);
|
||||
map.put("url", oss.getUrl());
|
||||
map.put("fileName", oss.getOriginalName());
|
||||
map.put("ossId", oss.getOssId().toString());
|
||||
return R.ok(map);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error(e.getMessage());
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user