Search in sources :

Example 6 with GridFSInputFile

use of com.mongodb.gridfs.GridFSInputFile in project play-cookbook by spinscale.

the class GridFsHelper method storeFile.

public static void storeFile(String title, File image) throws IOException {
    GridFS fs = getGridFS();
    // delete the old file
    fs.remove(image.getName());
    GridFSInputFile gridFile = fs.createFile(image);
    gridFile.save();
    gridFile.setContentType("image/" + FilenameUtils.getExtension(image.getName()));
    gridFile.setFilename(image.getName());
    gridFile.put("title", title);
    gridFile.save();
}
Also used : GridFSInputFile(com.mongodb.gridfs.GridFSInputFile) GridFS(com.mongodb.gridfs.GridFS)

Aggregations

GridFSInputFile (com.mongodb.gridfs.GridFSInputFile)6 GridFS (com.mongodb.gridfs.GridFS)3 DB (com.mongodb.DB)2 GridFSDBFile (com.mongodb.gridfs.GridFSDBFile)2 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBCursor (com.mongodb.DBCursor)1 DBObject (com.mongodb.DBObject)1 Mongo (com.mongodb.Mongo)1 MongoClient (com.mongodb.MongoClient)1 MongoClientURI (com.mongodb.MongoClientURI)1 FloatArrayInputStream (de.fhg.igd.mongomvcc.helper.FloatArrayInputStream)1 IMongodConfig (de.flapdoodle.embed.mongo.config.IMongodConfig)1 MongoCmdOptionsBuilder (de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder)1 MongodConfigBuilder (de.flapdoodle.embed.mongo.config.MongodConfigBuilder)1 Net (de.flapdoodle.embed.mongo.config.Net)1 Storage (de.flapdoodle.embed.mongo.config.Storage)1