首页 > 解决方案 > 尝试返回图像 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项目中文件的位置,我该如何解决?

标签: javaspring-bootrest

解决方案


推荐阅读