\S3FileUploadField
Extends the SilverStripe UploadField to allow it to upload file to an S3 Bucket instead of the local storage.
- Author: Maxime Rainville <max@firebrand.nz>
Synopsis
class S3FileUploadField
extends UploadField
{
- // members
- protected string $templateFileButtons = 'S3UploadField_FileButtons';
- protected boolean $bucket = false;
- protected boolean $region = false;
- private static array $allowed_actions = ;
- // methods
- public void __construct()
- public SS_viewable Field()
- public string getBucket()
- public S3FileUploadField setBucket()
- public string getRegion()
- public S3FileUploadField setRegion()
- protected array getFormData()
- public string getBucketUrl()
- public SS_HTTPResponse upload()
- public S3FileUploadField_ItemHandler getItemHandler()
- public void getRelationAutosetClass()
Hierarchy
Extends
- UploadField
Members
private
- $allowed_actions
—
array
Possible actions on this fields
protected
- $bucket
—
string
Name of the bucket where the file will be uploaded. - $region
—
string
Name of the AWS region where the bucket is lcoated. - $templateFileButtons
—
string
We'll use a different template to render the buttons on the upload field because our actions are slightly different.
Methods
protected
- getFormData() — Generate the Form Data that will be passed along our upload request to AWS S3. This data will include signature based on our AccessID and secret. This will confirm to AWS that this upload request is legit.
public
- __construct() — Override the standard UploadField constructor so we can set a few things.
- Field() — Return our field for display in SS template
- getBucket() — Get the S3 bucket name where the file will be uplaoded.
- getBucketUrl() — Get the URL of our bucket based off the bucket name and its region.
- getItemHandler()
- getRegion() — Get the AWS Region where the bucket is lcoated
- getRelationAutosetClass() — Gets the foreign class that needs to be created, or 'S3File' as default if there is no relationship, or it cannot be determined.
- setBucket() — Explicitly define the bucket to which the file will be uploaded.
- setRegion() — Explicitly define the region in which the bucket is located
- upload() — Once the file has been uploaded to S3, the CMS will callback this action and pass along details about the file that we'll use to create an S3File DataObject.