Kentico CMS 7.0 Developer's Guide

Amazon S3

Amazon S3

Previous topic Next topic Mail us feedback on this topic!  

Amazon S3

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Configuring Kentico CMS to use Amazon S3

 

1. Make sure you that have your Amazon S3 account set up and and that you have created at least one bucket.

 

2. Add the following key into the appSettings section of your web.config. This key specifies that CMS.IO will use the Amazon S3 provider..

 

<add key="CMSExternalStorageName" value="amazon" />

 

3. Add the following key into the appSettings section of your web.config. This key specifies the bucket which you want to use to store files. Replace the value with the name of the bucket.

 

<add key="CMSAmazonBucketName" value="YourBucketName" />

 

4. Specify the ID of your Amazon access key by inserting the following key into the appSettings section of your web.config.

 

<add key="CMSAmazonAccessKeyID" value="YourKey" />

 

5. Specify the Amazon access key by adding the following key into the appSettings section of your web.config.

 

<add key="CMSAmazonAccessKey" value="YourSecret" />

 

After you save your web.config, Kentico CMS starts storing its files in the specified Amazon S3 bucket.

 

You can configure the following optional settings:

 

Key

Description

Sample Value

CMSAmazonTempPath

Path to a local directory that will be used for storing temporary files. If you don't specify a value, the provider will use the default operating system temporary directory.

<add key="CMSAmazonTempPath" value="C:\Windows\Temp" />

CMSAmazonCachePath

Path to a local directory where the provider will store cached files. If you don't use this setting, the system will create a directory in the default operating system temporary directory.

<add key="CMSAmazonCachePath" value="C:\Cache" />

CMSAmazonEndPoint

Allows to change the default endpoint, for example when you want to use CloudFront CDN.

 

The default endpoint address is http://<yourbucketname>.s3.amazonaws.com

<add key="CMSAmazonEndPoint" value="http://someendpoint.s3.amazonaws.com" />

CMSAmazonPublicAccess

Specifies whether files uploaded to Amazon S3 through Kentico CMS will be accessible for public users.

 

The default value is true if you specify an endpoint. If no endpoint is specified, the default value is false.

<add key="CMSAmazonPublicAccess" value="true"/>

 

Storing files in different buckets

 

By default, the system stores files in a single bucket. However, the built-in Amazon S3 storage provider allows you to specify sections of the file system, which will be stored in a different bucket.

 

1. Open the CMSHttpApplication.cs file from the App_Code\Application folder.

 

2. Add a using statement for CMS.IO.

 

3. In the Application_Start method, create a new instance of the Amazon S3 storage provider.

 

AbstractStorageProvider mediaProvider = new StorageProvider("Amazon", "CMS.AmazonStorage");

 

4. Specify the target bucket using the CustomRootPath property of the provider.

 

mediaProvider.CustomRootPath = "mymediabucket";

 

Optionally, you can specify whether you want the bucket to be publicly accessible using the PublicExternalFolderObject property of the provider. True means the bucket is publicly accessible.

 

mediaProvider.PublicExternalFolderObject = true;

 

5. Use the following code to map a directory to the provider you've instantiated in step 3. This is the directory that you want to store in the bucket.

 

StorageHelper.MapStoragePath("~/MySite/Media/", mediaProvider);

 

7. Save the file.

 

8. If you're using web application, rebuild the solution.