Abstracts file storing infrastructure. Allows to change storage when deploying/testing an app, caching stored files stats, and so on.
Currently bundled storages:
- Local file system
- Amazon S3
Use the plugin, post your feedback!
Current release: 0.2-SNAPSHOT
Add to your BuildConfig.groovy
:
grails.project.dependency.resolution = {
...
repositories {
...
mavenRepo "http://mvn.quonb.org/repo"
grailsRepo "http://mvn.quonb.org/repo", "quonb"
...
}
plugins {
compile 'infra-file-storage:0.2-SNAPSHOT'
...
}
Use Config.groovy
to change the defaults:
plugin{
infraFileStorage {
local {
localRoot = "./web-app/" // (optional) where to store local files
defaultBucket = "storage" // (optional) will appear as a folder in your localRoot
urlRoot = "/mirari/" // (optional) Set absolute path to localRoot
}
s3 {
defaultBucket = "(required) name of your Amazon S3 Bucket to be used for default"
accessKey = "ACCESS KEY"
secretKey = "SECRET KEY"
urlRoot = "http://statics.example.com/" // (optional) This will be used to make URLs for your files
buckets { // optional
bucketName = "http://customUrlRoot"
}
}
defaultStorageName = "local" // a storage name to use
}
}
}
}
Take a look on Spock Integration tests
def holder = fileStorageService.getManager(path, bucket, false)
This method will return you a manager instance to manage files in a bucked
and path
, without caching files stats in database.
You may take a look on available methods there: FilesManager
A more sophisticated way to manage files is to annotate its holder (e.g. domain object) with FilesHolder annotation
If you set enableFileDomains
option of an annotation to true
(default is true
), file stats will be stored in database. To change the stats persisting strategy, take a look there: beans to override.