Tag: gridfs stream

如何在Spring Rest Call中使用GridFS从Mongo发送检索到的图像?

我使用Spring Data和GridFs Template从Mongo DB中检索了图像 所以我不知道如何将检索到的输入流提供给用户。 假设他们要求http://host.com/apple作为春季rest电话 。 现在我的应用程序使用名称apple处理请求,它从mongodb数据库中检索苹果图像。 现在没有保存在任何地方我想将响应显示为用户的图像,将在浏览器中显示http://host.com/apple图像。 我究竟需要如何实现这个? 你可以分享任何代码库来处理Rest Call中的图像请求吗? Controller Code @RestController public class GreetingController { @RequestMapping(“/image”) public GridFSDBFile imageReponse() { App.getImage(); return App.getImageResponse(); } } 此函数将从mongodb中获取图像 public static GridFSDBFile getImageResponse() { try { ApplicationContext context = new FileSystemXmlApplicationContext( “file:C:\\workspace\\gs-rest-service-complete\\spring-config.xml”); FileStorageDao fileStorageDao = (FileStorageDao) context .getBean(“fileStorageDao”); GridFSDBFile retrive = fileStorageDao.retrive(“audi.jpg”); return retrive; […]