List of usage examples for org.springframework.data.mongodb.gridfs GridFsResource getInputStream
@Override public InputStream getInputStream() throws IOException, IllegalStateException
From source file:piecework.util.ContentUtility.java
public static ContentResource toContent(GridFsResource resource) throws IOException { String resourceId = resource.getId().toString(); return new BasicContentResource.Builder().contentId(resourceId).contentType(resource.getContentType()) .filename(resource.getFilename()).location(resource.getFilename()) .inputStream(resource.getInputStream()).lastModified(resource.lastModified()) .length(Long.valueOf(resource.contentLength())).build(); }
From source file:com.greglturnquist.springagram.fileservice.mongodb.ApplicationController.java
@RequestMapping(method = RequestMethod.GET, value = "/files/{filename}") public ResponseEntity<?> getFile(@PathVariable String filename) { GridFsResource file = this.fileService.findOne(filename); if (file == null) { return ResponseEntity.notFound().build(); }/*from w w w.j a v a 2 s. c o m*/ try { return ResponseEntity.ok().contentLength(file.contentLength()) .contentType(MediaType.parseMediaType(file.getContentType())) .body(new InputStreamResource(file.getInputStream())); } catch (IOException e) { return ResponseEntity.badRequest().body("Couldn't process the request"); } }