spring - 如何访问@RequestParam 以在 Spring Rest 控制器中获取文件名
问题描述
我想以另一种方法使用此端点上传文件名
@PostMapping("/uploadFile")
public UploadFileResponse uploadFile(@RequestParam("file") MultipartFile
file) {
String fileName = fileStorageService.storeFile(file);
String fileDownloadUri =
ServletUriComponentsBuilder.fromCurrentContextPath()
.path("/downloadFile/")
.path(fileName)
.toUriString();
return new UploadFileResponse(UUID.randomUUID(), fileName, fileDownloadUri, file.getContentType(), file.getSize());
}
另一种方法是将文件名与一些数据一起发送到 mongodb。
@PostMapping("/uploadPath")
public String setPath(@RequestBody Image image ) {
image.setImageId(UUID.randomUUID());
String fileName = m.
image.setFileName(fileName);
String filePath = Paths.get(fileStorageProperties.getUploadDir()).toAbsolutePath().normalize()+File.separator+fileName;
image.setImagePath(filePath);
imgserv.insertPath(image);
}
是否可以从端点(/uploadFile)访问文件名并使用端点(/uploadPath)存储在数据库中
解决方案
推荐阅读
- python - 如何迭代多个数据帧并将值添加到python中的新数据帧
- r - 为什么单选按钮不适用于两个不同的 tabPanel()s(闪亮的应用程序)中的日期输入选择?
- facebook - 如何在不使用登录的情况下使用令牌初始化 Facebook Javascript SDK?
- python - 如何在 matplotlib 中绘制日期
- arm - 为什么mbed生成不同大小的bin文件在线编译和离线编译(导出gcc_arm makefile)
- sorting - 为什么这两个 GREP 命令给出不同的结果?
- sql-server - SQL组合两个具有相同行数的表的列
- jquery - 猫头鹰轮播已显示后的无效延迟加载
- xquery - 使用触发器评估 xQuery 并在 eXistDB 中的 HTML 页面内使用 return
- reactjs - 部署后 React BrowserRouter 路由不起作用