Inheritance: Amazon.S3.Model.S3Response
Beispiel #1
0
        public async Task UploadFile(string filePath, string s3Bucket, string newFileName, bool deleteLocalFileOnSuccess)
        {
            //save in s3
            Amazon.S3.Model.PutObjectRequest s3PutRequest = new Amazon.S3.Model.PutObjectRequest();
            s3PutRequest            = new Amazon.S3.Model.PutObjectRequest();
            s3PutRequest.FilePath   = filePath;
            s3PutRequest.BucketName = s3Bucket;
            //s3PutRequest.ContentType = contentType;

            //key - new file name
            if (!string.IsNullOrWhiteSpace(newFileName))
            {
                s3PutRequest.Key = newFileName;
            }

            s3PutRequest.Headers.Expires = new DateTime(2020, 1, 1);

            try
            {
                Amazon.S3.Model.PutObjectResponse s3PutResponse = await S3Client.PutObjectAsync(s3PutRequest);

                if (deleteLocalFileOnSuccess)
                {
                    //Delete local file
                    if (System.IO.File.Exists(filePath))
                    {
                        System.IO.File.Delete(filePath);
                    }
                }
            }
            catch (Exception ex)
            {
                //handle exceptions
            }
        }
 public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) 
 {   
     PutObjectResponse response = new PutObjectResponse();
     
     UnmarshallResult(context,response);                        
          
                 
     return response;
 }
        private static void UnmarshallResult(XmlUnmarshallerContext context,PutObjectResponse response)
        {
            

            IWebResponseData responseData = context.ResponseData;
            if (responseData.IsHeaderPresent("x-amz-expiration"))
                response.Expiration = new Expiration(responseData.GetHeaderValue("x-amz-expiration"));
            if (responseData.IsHeaderPresent("x-amz-server-side-encryption"))
                response.ServerSideEncryptionMethod = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption"));
            if (responseData.IsHeaderPresent("ETag"))
                response.ETag = S3Transforms.ToString(responseData.GetHeaderValue("ETag"));
            if (responseData.IsHeaderPresent("x-amz-version-id"))
                response.VersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-version-id"));            


            return;
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context,PutObjectResponse response)
        {
            

            IWebResponseData responseData = context.ResponseData;
            if (responseData.IsHeaderPresent("x-amz-expiration"))
                response.Expiration = new Expiration(responseData.GetHeaderValue("x-amz-expiration"));
            if (responseData.IsHeaderPresent("x-amz-server-side-encryption"))
                response.ServerSideEncryptionMethod = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption"));
            if (responseData.IsHeaderPresent("ETag"))
                response.ETag = S3Transforms.ToString(responseData.GetHeaderValue("ETag"));
            if (responseData.IsHeaderPresent("x-amz-version-id"))
                response.VersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-version-id"));
            if (responseData.IsHeaderPresent(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader))
                response.ServerSideEncryptionKeyManagementServiceKeyId = S3Transforms.ToString(responseData.GetHeaderValue(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader));
            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderRequestCharged))
                response.RequestCharged = RequestCharged.FindValue(responseData.GetHeaderValue(S3Constants.AmzHeaderRequestCharged));

            return;
        }
Beispiel #5
0
        public string UploadFile(S3Request model)
        {
            //- Build Put Object
            var s3PutRequest = new Amazon.S3.Model.PutObjectRequest
            {
                FilePath   = model.FilePath,
                BucketName = S3Bucket,
                CannedACL  = Amazon.S3.S3CannedACL.PublicRead
            };

            if (!string.IsNullOrWhiteSpace(model.NewFileName))
            {
                s3PutRequest.Key = model.NewFileName;
            }

            try
            {
                Amazon.S3.Model.PutObjectResponse s3PutResponse = this.S3Client.PutObject(s3PutRequest);

                if (model.DeleteLocalFileOnSuccess)
                {
                    if (System.IO.File.Exists(model.FilePath))
                    {
                        System.IO.File.Delete(model.FilePath);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            string url = ServiceUrl + "/" + S3Bucket + "/" + model.NewFileName;

            return(url);
        }
Beispiel #6
0
        protected internal virtual S3PutInfo CreateS3PutInfo(PutObjectResponse response, string bucket, string path)
        {
            var eTag = response.ETag;
            var versionId = response.VersionId;
            var encryptionMethod = response.ServerSideEncryptionMethod.ToString();
            var putDate = SystemTime.Now();
            #if DEBUG
            for (int i = 0; i < response.Headers.Count; i++)
            {
                var h = response.Headers[i];
                System.Diagnostics.Debug.WriteLine(String.Format("{0}: {1}", h, response.Headers[h]));
            }
            #endif

            return new S3PutInfo
                       {
                           BucketName = bucket,
                           Path = path,
                           ServiceUrl = _config.ServiceURL,
                           Scheme = _config.CommunicationProtocol.ToString(),
                           ETag = eTag,
                           VersionId = versionId,
                           EncryptionMethod = encryptionMethod,
                           PutDate = putDate,
                       };
        }