Skip to content

A Grails plugin to provide multi purpose file uploader functionality.

License

Notifications You must be signed in to change notification settings

wizpanda/multi-file-upload

Repository files navigation

Grails Multi File Upload

GitHub version Release

A plugin for multi-purpose file upload functionality for Grails 3+ application. This plugin allows uploading & saving files to the following destinations:

  1. To the local server or the local system.
  2. To the Amazon S3 storage (can be deleted as well).

The upload APIs are highly customizable, so you can always override the classes or add your own implementation.

Installation & Usage

Installation

Add the following to build.gradle file of your Grails 3 application

Under repositories section

maven { url "https://jitpack.io" }

Under dependencies section

compile "com.wizpanda:multi-file-upload:<version>"

Configuration

In the application.groovy file, define your groups & AWS configuration. For example:

fileUpload {
    global {
        amazon {
            accessKey = "EXAMPLE-KEY-ALIAI4VT211NNPSV3YGQ2"
            accessSecret = "EXAMPLE-SECRET-803a3E2Ul0HkImA2kLQAyF4ngM3P6St"
        }
    }
    groups {
        fooSliderImages {
            // Add the service which you want to configure here
            service = com.wizpanda.file.service.AmazonS3UploaderService
            container = "foo-images"
            cacheControlSeconds = 604800    // 1 week
        }
    }
}

Read docs/aws-access-configuration.md to read how to get the access key & secret for AWS S3.

Using in controllers or services

fileUploadService.save(params.file, "fooSliderImages")

Uses of containers/buckets

The containers defined in the configuration above i.e. foo-images are suffixed with environment name for non-production environment. For example, an S3 container with the name foo-images-development will be used when running locally. So that container must be there before.

This means, you don't need to use Grails environments to use the different buckets for different environments.