How to send an retrieved image from Mongo using GridFS in Spring Rest Call?

限于喜欢 提交于 2019-12-03 08:49:10
ajayramesh

I have used the spring boot and rest where this following code will work if you are using latest version of spring i.e.,Spring 4.1

@RequestMapping(value = "/image", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity<InputStreamResource> getImage() {
        GridFSDBFile gridFsFile = App.getImageResponse();

        return ResponseEntity.ok()
                .contentLength(gridFsFile.getLength())
                .contentType(MediaType.parseMediaType(gridFsFile.getContentType()))
                .body(new InputStreamResource(gridFsFile.getInputStream()));
    }

I followed this post , Check out . Spring MVC: How to return image in @ResponseBody?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!