PHPackages                             firebrandhq/s3fileupload - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. firebrandhq/s3fileupload

ActiveSilverstripe-module[File &amp; Storage](/categories/file-storage)

firebrandhq/s3fileupload
========================

Extend the SilverStripe UploadField to allow storing file in Amazone S3

v1.0.0(10y ago)24903MITPHP

Since Jul 16Pushed 10y ago3 watchersCompare

[ Source](https://github.com/firebrandhq/s3fileupload)[ Packagist](https://packagist.org/packages/firebrandhq/s3fileupload)[ RSS](/packages/firebrandhq-s3fileupload/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

Firebrand SilverStripe S3FileUpload
===================================

[](#firebrand-silverstripe-s3fileupload)

This SilverStripe plugin allows file to be uploaded directly to S3 and track as SilverStripe DataObjects.

Requirements
------------

[](#requirements)

- SilverStripe 3.1
- AWS SDK for PHP v3

Installation
------------

[](#installation)

Install the module through [composer](http://getcomposer.org):

```
composer require firebrandhq/s3fileupload
```

Setting up your S3 bucket
-------------------------

[](#setting-up-your-s3-bucket)

To be able to do a direct up load to S3, your bucket must have CORS Configuration. To Set up your CORS configuration:

1. Log into S3 and access your bucket.
2. Select *Properties* to view your bucket properties.
3. Under *Permission*, select *Edit CORS Configuration*.
4. In the pop up, input your CORS configuration in XML format.

### Sample CORS configuration

[](#sample-cors-configuration)

```

        http://example.com
        POST
        3000
        Location
        *

        https://dev.example.com
        POST
        3000
        Location
        *

        http://localhost
        POST
        3000
        Location
        *

```

Note that you'll need a separate `CORSRule` entry for each domain from which you plan to upload files.

You'll also need a `CORSRule` entry for each protocol.

Getting an Access Key and a Secret
----------------------------------

[](#getting-an-access-key-and-a-secret)

You'll need to generate an AWS Access Key ID and Secret Access Key to allow SilverStripe to communicate with S3.

For security reasons, it is **STRONGLY RECOMMENDED** to create a new user with limited access. This will minimise the damage should your Access Key and/or Secret ever be compromised.

### Sample Policy for your AWS user

[](#sample-policy-for-your-aws-user)

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:ListAllMyBuckets",
            "Resource": "arn:aws:s3:::*"
        },
        {
            "Effect": "Allow",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::name-of-your-bucket",
                "arn:aws:s3:::name-of-your-bucket/*"
            ]
        }
    ]
}
```

Configuring SilverStripe
------------------------

[](#configuring-silverstripe)

You can use a YML config file to tell SilverStripe how to access your bucket.

Create a `s3.yml` file in `mysite/_config`.

```
S3File:
  Bucket: 'name-of-your-bucket'
  Region: 'us-east-1'
  AccessId: 'YOUACCESSKEYID'
  Secret: 'YOURACCESSKEYSECRET'
```

You don't have to provide the Bucket or Region in YML file if you don't want to. Those can be manually set on your S3FileUploadField.

Adding an S3File to a SilverStripe DataObject/Page
--------------------------------------------------

[](#adding-an-s3file-to-a-silverstripe-dataobjectpage)

```
