Ejemplo n.º 1
0
        public int UploadRecordAndBankStatementImagesToS3ByTransferUtil(string transactionType, int currentClientId, string imageName, string imagePath, string keyName, Stream file, string transferYear, string transferMonth)
        {
            try
            {
                using (var client = new AmazonS3Client(awsAccessKeyId, awsSecretAccessKey, Amazon.RegionEndpoint.EUWest2))
                //  using (var client = new AmazonS3Client(Amazon.RegionEndpoint.EUWest2))
                {
                    string objectKey = AppSettingsUtil.GetPathForKeyNameBucketForRecordAndBankStatementTransaction(transactionType, currentClientId, transferYear, transferMonth);
                    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);
            }
        }