Example usage for org.springframework.data.mongodb.gridfs GridFsResource getContentType

List of usage examples for org.springframework.data.mongodb.gridfs GridFsResource getContentType

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.gridfs GridFsResource getContentType.

Prototype

@SuppressWarnings("deprecation")
public String getContentType() 

Source Link

Document

Returns the Resource 's content type.

Usage

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:org.swarmcom.jsynapse.dao.ContentRepositoryImpl.java

@Override
public ContentResource download(String mediaId) {
    GridFSDBFile file = gridFsTemplate.findOne(Query.query(Criteria.where("_id").is(mediaId)));
    if (null == file) {
        return null;
    }//from   w ww. j a  v  a2 s  . com
    GridFsResource gridFsResource = new GridFsResource(file);
    return new ContentResource(gridFsResource.getContentType(), file.getLength(), gridFsResource);
}

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  ww .ja  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");
    }
}