Ejemplo n.º 1
0
        /// <summary>
        /// To upload object to AWS S3 Bucket
        /// </summary>
        /// <param name="transactionType"></param>
        /// <param name="currentClientId"></param>
        /// <param name="imageName"></param>
        /// <param name="imagePath"></param>
        /// <param name="keyName"></param>
        /// <returns></returns>
        public int UploadImagesToS3ByTransferUtil(string transactionType, int currentClientId, string imageName, string imagePath, string keyName, Stream file)
        {
            try
            {
                using (var client = new AmazonS3Client(awsAccessKeyId, awsSecretAccessKey, Amazon.RegionEndpoint.EUWest2))
                //  using (var client = new AmazonS3Client(Amazon.RegionEndpoint.EUWest2))
                {
                    string objectKey = AppSettingsUtil.GetPathForKeyNameBucket(transactionType, currentClientId);
                    objectKey = objectKey + "/" + keyName;

                    using (var transferUtility = new TransferUtility(client))
                    {
                        //Creates PutObjectRequest of AmazonS3
                        var transferUtilityUploadRequest = new TransferUtilityUploadRequest
                        {
                            BucketName  = bucketName,
                            Key         = objectKey,
                            InputStream = file
                        };

                        //Adds an object to a bucket
                        transferUtility.Upload(transferUtilityUploadRequest);
                        MakeImagePublicReadOnly(objectKey);
                        File.Delete(imagePath);

                        return(currentClientId);
                    }
                }
            }
            catch (Exception ex)
            {
                Program.ErrorLogging(ex);
                return(0);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// To upload object to AWS S3 Bucket
        /// </summary>
        /// <param name="transactionType"></param>
        /// <param name="currentClientId"></param>
        /// <param name="imageName"></param>
        /// <param name="imagePath"></param>
        /// <param name="keyName"></param>
        /// <returns></returns>
        public int UploadImagesToS3(string transactionType, int currentClientId, string imageName, string imagePath, string keyName)
        {
            try
            {
                using (var client = new AmazonS3Client(awsAccessKeyId, awsSecretAccessKey, Amazon.RegionEndpoint.EUWest2))
                //  using (var client = new AmazonS3Client(Amazon.RegionEndpoint.EUWest2))
                {
                    string objectKey = AppSettingsUtil.GetPathForKeyNameBucket(transactionType, currentClientId);
                    objectKey = objectKey + "/" + keyName;

                    //Creates PutObjectRequest of AmazonS3
                    var putObjectRequest = new PutObjectRequest
                    {
                        BucketName = bucketName,
                        Key        = objectKey,
                        FilePath   = imagePath,
                    };

                    //Adds an object to a bucket
                    client.PutObject(putObjectRequest);
                    File.Delete(imagePath);
                    return(currentClientId);
                }
            }
            catch (Exception ex)
            {
                Program.ErrorLogging(ex);
                return(0);
            }
        }