前言:
最近在对系统的文件上传进行统一管理,发现后端的文件上传接口需要修改.原来的文件管理只是单纯的随机数+文件名为存储路径,修改的方案是不同的业务文件上传的路径为业务名+自定义分类机制(可选,可多层级)+文件名
原先的接口代码:
@GetMapping(value = "/files/{uuid}/{filename:.+}")
public ResponseEntity<Resource> serveFile(@PathVariable String filename,
@PathVariable String uuid) throws Exception {
Resource file = storageService.loadAsResource(filename, uuid);
filename = URLDecoder.decode(filename, "UTF-8");
filename = new String(filename.getBytes("gbk"), "iso-8859-1");
String headerValue = "attachment; filename=" + filename;
return ResponseEntity
.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, headerValue)
.body(file);
}
由上可见,该接口仅支持 api/随机数/文件名 的上传路径
但修改后的文档上传接口需要满足多层的上传路径
比如: api/业务名/文件名