Created
February 12, 2010 16:04
-
-
Save efleming969/302687 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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