Discuss

Using S3 Connector

On this page

What is S3 Connector

S3 Connector allows you to connect to AWS and Digital Ocean cloud storage services, create buckets, list/put/get/delete files, create signed URLs and more.

Now as you know how to setup S3 on AWS and Digital Ocean you are ready to use the S3 Connector in Server Connect.

Setting up S3 Provider

Using the S3 Connector is really easy. First create a Server Action:

Screenshot_22|690x392

Right click steps:

Screenshot_23|690x392

Select S3 Connector and click S3 Provider:

Screenshot_24|690x392

Select the Service you want to use: AWS, Digital Ocean or a Custom Service. We select AWS:

Screenshot_25|690x392

Select your region:

Screenshot_26|690x392

And enter the Access Key ID and the Secret Access Key for your user:

Screenshot_27|690x392

Now, as we've set up the S3 Provider we can do different things, such as listing our buckets, list/get/put/delete files from a bucket, create a bucket or delete existing one etc.

Listing Buckets

A simple example of what you can do with the S3 Connector would be to list our buckets. So right click the S3 Provider step, open the S3 Connector menu and select S3 List Buckets:

Screenshot_28|690x392

Save your Server Action:

Screenshot_29|690x392

And click the Open in Browser button to preview the results:

Screenshot_31|690x392

You can see the S3 Bucker we've set up earlier in AWS with some additional info.

Uploading Files to a Bucket

There are two ways of uploading files to a Bucket using the S3 Connector. The first option is to upload a file which already exists on your server and the other one is to use a form on a regular page and the File Uploader component available in Server Connect. Let's use an upload form.

First we need a simple HTML page containing a form with a file input and a submit button inside. Make sure the Method is set to POST and save your page:

Screenshot_1|690x392

Open Server Connect and create a new Server Action:

Screenshot_2|690x392

Select Globals and click the browse button in the linked page field. Select your HTML page there:

Screenshot_4|690x392

Then select your form in the dropdown:

Screenshot_5|690x392

And click the Import From Form button:

Screenshot_6|690x392

Your file input has been imported under the Global $_POST variables:

Screenshot_7|690x392

Right click steps:

Screenshot_8|690x392

And add add the S3 Provider:

Screenshot_9|690x392

Setup the S3 Provider as explained earlier in this tutorial:

Screenshot_10|690x392

Right click the S3 Provider step and add File Upload:

Screenshot_11|690x392

Select your upload field:

Screenshot_12|690x392

We select our file input, imported under $_POST:

Screenshot_14|690x392

Select an upload path on your server:

Screenshot_15|690x392

The files will be uploaded into /uploads/bucket on our server:

Screenshot_16|690x392

Then, we want to send them to our bucket. So right click the Upload step, open S3 Connector and select Put File:

Screenshot_17|690x392

Enter your bucket name, or select a dynamic value returning it. We just enter our bucket name here for this tutorial:

Screenshot_18|690x392

Then, select a dynamic value for the Key option (that's how your file will be called in the bucket):

Screenshot_19|690x392

We will use the uploaded file name, so select name under the upload step:

Screenshot_20|690x392

Then select a dynamic value for the file path:

Screenshot_21|690x392

This should be the upload path returned by our upload step:

Screenshot_22|690x392

Select the access to the file Private or Public Read:

Screenshot_23|690x392

Save your server action and close the Server Connect panel:

Screenshot_24|690x392

Select your form on the page and click the Make Server Action Form button:

Screenshot_26|690x392

Then select a server action for this form:

Screenshot_27|690x392

Select the bucketupload server action, which we just created:

Screenshot_28|690x392

Setup any redirect, alert, form reset or any other action that needs needs to run when the file has been successfully uploaded. We won't show this now, as it's already documented in other tutorials.

Save your page and preview the results in your browser:

Screenshot_29|690x392

You can see the file has been uploaded in the Bucket when you open the AWS Console and view your Bucket:

Screenshot_30|690x392

Listing Files from a Bucket

Another simple example of what you can do with the S3 Connector is to list the files from a bucket.

First, create a Server Action:

Screenshot_1|690x392

Then right click steps and add S3 Provider. Setup the S3 Provider as explained earlier in this tutorial:

Screenshot_2|690x392

Then right click S3 Provider step:

Screenshot_3|690x392

Open S3 Connector and select S3 List Files:

Screenshot_4|690x392

Enter the name of the Bucket which files you want to list, or select a dynamic value for it. In our tutorial we just use a static Bucket name:

Screenshot_5|690x392

Then setup the list options, such as the max number of records to return, the prefix of the files you want to return etc. (check the info tooltips for more detailed information). We leave these options to their default values:

Screenshot_7|690x392

Save your server action:

Screenshot_8|690x392

You can preview the results by opening the server action in your browser:

Screenshot_9|690x392

And you can see the files list returned in your browser:

Screenshot_12|690x392