Grails plugin for storing files on AWS S3, caching them locally, and piping them through the application.
- Add
"/file/$path**"(controller:"file/get")to UrlMappings.groovy - Set
"/file/**"topermitAllin Config.groovy under Spring Security - Change bucket to the appropriate AWS S3 bucket name.
- Customize any other default configs by following the instructions below
- If cache is true and you want the cache to regularly update inject
cacheServiceinto BootStrap.groovy and callcacheService.startJob()at the end ofinit
- If cache is true and you want the cache to regularly update inject
- The project must be run using
-Daws.accessKeyId=[myKey]and-Daws.secretKey=[mySecretKey]denoting AWS credentials with S3 permissions
All config items can be overwritten in Config.groovy by prepending grails.plugin.awsfiles. onto the option name.
Boolean for if local caching of files is on.
Default - true
Path of where cached files are stored. Only used if cache is true.
Default - 'cache'
Turning on cacheSync keeps the local cache in sync with the remote bucket, not just up to date with the latest files. This means the plugin will delete local files which are not in S3. Make sure the cacheLocation is for cache items only, otherwise the other items will be deleted.
Default - false
Boolean for if byte range support is on.
Default - false
Time between cache refreshes in ms. Only used if cache is true and cacheService.startJob() was called in the BootStrap.groovy.
Default - 300000
Array of file endings for file types which will be rendered inline in the browser when browsed to.
Default - ['txt', 'pdf', 'html']
Map of file endings to file endings of file types whose file ending will be changed during retrieval. For example, if html is mapped to md and MyFile.html is requested the plugin will look for a file named MyFile.md and if it exists the plugin will return a map of the contents of MyFile.md and the real file ending of the file. The form of the map returned is [contents: fileContents, type: fileEnding] where fileContents is the file contents and fileEnding is the real file ending.
A use case is rendering markdown files inline. If MyFile.md is requested the file will be downloaded because markdown files can not be rendered inline by the browser. To get around this html can be mapped to md and when MyFile.html is requested the contents of MyFile.md will be returned. This contents can then be sent to the get.gsp page where it can be rendered based on the real file type.
Default - ['html': 'md']
The name of the AWS S3 bucket serving as the virtual directory.
The size of the buffer used to retrieve files from S3 in bytes.
Default - 1000000
Boolean for if the files in S3 are encrypted.
Default - false
Encryption key for files in S3. Required if encrypt is true.
AWS Files has been released under the MIT license by SRA International, INC. It was originally developed specifically for the SRA Rapid Application Development Team.