This is a migrated thread and some comments may be shown as answers.

How to specify AmazonS3 properties with RadCloudUpload

1 Answer 128 Views
CloudUpload
This is a migrated thread and some comments may be shown as answers.
ERIC
Top achievements
Rank 1
ERIC asked on 07 Oct 2015, 07:58 AM

Hello,

I will wish to clarify the following  properties :
- StorageClass
- ServerSideEncryptionMethod 
- CannedACL
 I do not see how, thank you for your help.

 Vincent

1 Answer, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 09 Oct 2015, 07:32 AM
Hi Eric,

You will have to create a Custom Amazon Provider and override the UploadFile method to change the default S3 properties:
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using Telerik.Web.UI;
 
namespace MyNamespace
{
    public class CustomAmazonProvider : AmazonS3Provider
    {
        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            AccessKey = "{ACCESS_KEY}";
            SecretKey = "{SECRET_KEY}";
            BucketName = "{BUCKET_NAME}";
            UncommitedFilesExpirationPeriod = TimeSpan.FromHours(2);
        }
 
        public override void UploadFile(string keyName, System.Collections.Specialized.NameValueCollection metaData, System.IO.Stream fileStream)
        {
 
            PutObjectRequest request = new PutObjectRequest() { Key = keyName, BucketName = BucketName, InputStream = fileStream };
            request.CannedACL = S3CannedACL.PublicRead;
 
            foreach (string key in metaData)
            {
                request.Metadata.Add(key, metaData[key]);
            }
 
            try
            {
                AmazonS3Client.PutObject(request);
            }
            catch (AmazonS3Exception e)
            {
                var message = string.Format("Exception thrown for upload operation for file with keyName: {0}", keyName);
                throw new CloudUploadProviderException(message, e, keyName, BucketName);
            }
 
        }
 
        public override string InitiateMultiPartUpload(string keyName, NameValueCollection metaData)
        {
            InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest();
            request.CannedACL = S3CannedACL.PublicRead;
 
            request.BucketName = BucketName;
            request.Key = keyName;
 
            foreach (string key in metaData)
            {
                request.Metadata.Add(key, metaData[key]);
            }
 
            InitiateMultipartUploadResponse response;
 
            try
            {
                response = AmazonS3Client.InitiateMultipartUpload(request);
            }
            catch (AmazonS3Exception e)
            {
                throw new CloudUploadProviderException("Exception thrown for initiate multi part upload operation", e);
            }
 
            return response.UploadId;
        }
    }
}

Sample: RadCloudUpload Amazon S3 Public Files

Regards,
Hristo Valyavicharski
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
CloudUpload
Asked by
ERIC
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Share this question
or