java - 尝试返回图像 REST API
问题描述
我的代码不适用于此 REST API 函数
@PostMapping(value = "/image", produces = MediaType.IMAGE_JPEG_VALUE)
public ResponseEntity<BufferedImage> getImage() {
BufferedImage img = null;
try{
img = ImageIO.read(new File("/static/images/agents/1.jpg"));
}
catch (IOException e)
{
e.printStackTrace();
}
return successResponse(img);
}
我收到异常“javax.imageio.IIOException:无法读取输入文件!”。这是我的spring boot项目中文件的位置,我该如何解决?
解决方案
推荐阅读
- python - 如何修复计数查询mysql(flask)中的输出
- php - 如何根据元素从php中的关联数组中选择数组
- node.js - 在 mongoose 中,根据 findOneAndUpdate 中另一个字段的值设置一个字段
- sql-server - 如何在 SSRS 中将 NaN 值更改为 0
- javascript - 如何强制 VueJS 在 css 中不生成“*、::after、::before”元素
- php - PHP:如何检索管道的东西
- assembly - MIPS:寄存器之间的区别
- ethereum - Ethereum/Truffle/Solidity:错误:tx 没有正确的随机数
- java - 根据从 thymeleaf 的下拉列表中选择的值迭代列表
- javascript - 单击动态生成的按钮