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;
|
package com.ruoyi.web.controller.common;
|
||||||
|
|
||||||
import com.ruoyi.common.core.AjaxResult;
|
import com.ruoyi.common.core.AjaxResult;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.system.domain.vo.SysOssVo;
|
import com.ruoyi.system.domain.vo.SysOssVo;
|
||||||
import com.ruoyi.web.service.ChunkedUploadService;
|
import com.ruoyi.web.service.ChunkedUploadService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.redisson.api.RMap;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Validated
|
@Validated
|
||||||
@RestController
|
@RestController
|
||||||
@@ -53,17 +57,18 @@ public class BigUploadController {
|
|||||||
* @return 合并结果及文件信息
|
* @return 合并结果及文件信息
|
||||||
*/
|
*/
|
||||||
@PostMapping("/merge")
|
@PostMapping("/merge")
|
||||||
public AjaxResult merge(@RequestParam("fileMd5") String fileMd5,
|
public R<Map<String, String>> merge(@RequestParam("fileMd5") String fileMd5,
|
||||||
@RequestParam("fileName") String fileName,
|
@RequestParam("fileName") String fileName,
|
||||||
@RequestParam("totalChunks") int totalChunks) {
|
@RequestParam("totalChunks") int totalChunks) {
|
||||||
try {
|
try {
|
||||||
SysOssVo oss = chunkedUploadService.mergeChunks(fileMd5, fileName, totalChunks);
|
SysOssVo oss = chunkedUploadService.mergeChunks(fileMd5, fileName, totalChunks);
|
||||||
return AjaxResult.success()
|
Map<String, String> map = new HashMap<>(2);
|
||||||
.put("url", oss.getUrl())
|
map.put("url", oss.getUrl());
|
||||||
.put("fileName", oss.getOriginalName())
|
map.put("fileName", oss.getOriginalName());
|
||||||
.put("ossId", oss.getOssId());
|
map.put("ossId", oss.getOssId().toString());
|
||||||
|
return R.ok(map);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return AjaxResult.error(e.getMessage());
|
return R.fail(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user