3
我已經從Mongo DB中使用Spring Data和GridFs檢索圖像如何在Spring Rest Call中使用GridFS從Mongo發送檢索的圖像?
所以我不知道如何將檢索到的輸入流提供給用戶。
說,他們要求爲
http://host.com/apple
爲彈簧安置通話。 現在我的應用程序使用名稱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;
} catch (Exception e) {
System.out.println("IOException:-" + e.getMessage());
} finally {
System.out.println("Clean up herer:-");
}
return null;
}
錯誤
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Sep 04 17:21:05 IST 2015
There was an unexpected error (type=Internal Server Error, status=500).
Could not write content: No serializer found for class com.mongodb.gridfs.GridFSDBFile$MyInputStream and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)) (through reference chain: com.mongodb.gridfs.GridFSDBFile["inputStream"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class com.mongodb.gridfs.GridFSDBFile$MyInputStream and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)) (through reference chain: com.mongodb.gridfs.GridFSDBFile["inputStream"])