Version 1, last updated by eltimn at May 05, 2011 12:56 UTC
Mongo GridFS
MongoDB GridFS supports storage of arbitrary length files using a chunked storage approach, see here for more details: http://www.mongodb.org/display/DOCS/GridFS
Assuming you’ve defined a default MongoDB connection in your Lift app, you can store a file using GridFS:
import com.mongodb.gridfs._
import net.liftweb.mongodb._
MongoDB.use(DefaultMongoIdentifier) { db =>
val fs = new GridFS(db)
val inputFile = fs.createFile(new java.io.File("/path/to/myfile"))
inputFile.setContentType("text/plain")
inputFile.setFilename("myfile")
inputFile.save
}
GridFS files can be retrieved in a number of ways, see: http://api.mongodb.org/java/current/com/mongodb/gridfs/GridFS.html
For example by filename:
MongoDB.use(DefaultMongoIdentifier) { db =>
val fs = new GridFS(db)
val foundFile = fs.findOne("myfile")
foundFile.writeTo("/path/to/myfoundfile")
}