Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
125 lines (93 sloc) 3.84 KB
Install:
grails install-plugin mongodb-gridfs
Configure:
<big>Adding the setting you're file path/to/app/grails-app/config/Config.groovy</big>
// host for mongodb
gridfsConfig.db.host = "localhost"
// db name
gridfsConfig.db.name = "myGridfs"
// collections for files
gridfsConfig.db.collection = "files"
// dir for icons
gridfsConfig.iconsdir = "images/icons"
// extensions images for thumbnail list
gridfsConfig.imagestype = ["jpg","gif","png","bmp"]
// allowedExtensions
gridfsConfig.allowedExtensions = ["jpg","gif","png","bmp","doc","rtf","zip"]
// tmp dir
gridfsConfig.tmpdir = "tmp/files"
// icon default
gridfsConfig.defaulticon = "images/icons/empty.png"
// file iconconfig.groovy in images dir
// format Extension : filename
// Example:
//iconsOfExtension = [
// pdf:"pdf.png",
// doc:"word.png"]
//template for dirs users thumbnails files
gridfsConfig.thumbconfig = [
publicdir:"tmp/imagesthumb/[idparent]",
x_size:128,
y_size:128
]
// max bites size
gridfsConfig.maxSize = 2000000
// default errors controller
gridfsConfig.controllers.errorController = "gridfs"
gridfsConfig.controllers.errorAction = "help"
// default controller for the success remove
gridfsConfig.controllers.successRemoveController = "gridfs"
gridfsConfig.controllers.successRemoveAction = "help"
// default controller for the success upload
gridfsConfig.controllers.successController = "gridfs"
gridfsConfig.controllers.successAction = "help"
// controller for the access deny
gridfsConfig.accessController = "gridfs"
gridfsConfig.accesssAction = "help"
// class name for access control
gridfsConfig.accessClass = "org.iglas.grails.utils.ExampleAccess"
// method name for access control
gridfsConfig.accessMethod = "check"
gridfsConfig.indexes = [
"metadata.idparent":1,
"metadata.parentclass":1]
Using:
Example controller:
class TestController {
def index() {
//get config
UserConfig gridfsConfig = new org.iglas.grails.utils.UserConfig("gridfsConfig")
//set user seting
gridfsConfig.set([controllers:[successController: "test",successAction:"index"]])
// using service
def list = new org.iglas.grails.gridfs.GridfsService().list([idparent: "myid",relative:true,icon:true])
render(view:"index", model:[listFiles: list ])
}
}
Example GSP:
<gridfs:form idparent="myid" parentclass="user" accesspolitic="['public','private','hidden']"
errorAction="index" errorController="test"
successAction="index" successController="test">
Description: <g:textField name="text" />
</gridfs:form >
<g:each in="${listFiles}">
name -> ${it.filename} <br />
text-> ${it.metadata?.text} <br />
// formatting size
size -> <gridfs:prettysize size="${it.size}" /> <br />
// get icon file path in list (invoke params icon=true)
icon -> <img src="${it.iconUrl}" /> <br />
// get link for download file
file- <gridfs:download filename="${it.filename}">${it.metadata.originalFilename}</gridfs:download>
// get icon custom size
<gridfs:getIcon filename="${it.filename}" title="myicon 150x200" x="150" y="200"/>
<gridfs:getIcon filename="${it.filename}" title="myicon 50x50" x="50" y="50"/>
// get link for file
<img src="${gridfs.createLink(filename:it.filename)}" width="200">
<br />
// get link for remove file
<gridfs:remove filename="${it.filename}">remove</gridfs:remove>
//using custom controllers action
<gridfs:remove filename="${it.filename}" errorAction="index" errorController="test">remove custom Controler</gridfs:remove>
<hr />
</g:each>
Something went wrong with that request. Please try again.