Skip to content

Instantly share code, notes, and snippets.

@efleming969
Created February 12, 2010 16:04
Show Gist options
  • Save efleming969/302687 to your computer and use it in GitHub Desktop.
Save efleming969/302687 to your computer and use it in GitHub Desktop.
package sudo.samples.resources
import sudo.restly.core.{GridFSRepresentation, RestlyResource}
import com.mongodb.gridfs.{GridFSDBFile, GridFS}
import org.restlet.resource.{Delete, Get}
import com.mongodb.{BasicDBObjectBuilder, BasicDBObject}
class FileResource extends RestlyResource {
@Get
def doRead() = {
getLogger.info("reading an extisting file: "+
getRequest.getAttributes.get("id").toString)
val gfs = new GridFS(mongo)
val file:GridFSDBFile = gfs.findOne(
getRequest.getAttributes.get("id").toString)
new GridFSRepresentation(file)
}
@Delete
def doDelete() = {
val id = getRequest.getAttributes.get("id").toString
getLogger.info("deleting an existing file: "+id)
val gfs = new GridFS(mongo)
gfs.remove(id)
getJsonRepresentation(BasicDBObjectBuilder.start("message", "done").get)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment