How to specify AmazonS3 properties with RadCloudUpload

2 posts, 0 answers
  1. ERIC
    ERIC avatar
    2 posts
    Member since:
    Jun 2014

    Posted 07 Oct 2015 Link to this post

    Hello,

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

     Vincent

  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 09 Oct 2015 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top