Created
December 7, 2018 18:19
-
-
Save amr-swalha/7d9c79c143cbd7968b78abd3aab53973 to your computer and use it in GitHub Desktop.
Writing an object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void WritingAnObject() | |
{ | |
try | |
{ | |
// simple object put | |
PutObjectRequest request = new PutObjectRequest() | |
{ | |
ContentBody = "this is a test", | |
BucketName = bucketName, | |
Key = keyName | |
}; | |
PutObjectResponse response = client.PutObject(request); | |
// put a more complex object with some metadata and http headers. | |
PutObjectRequest titledRequest = new PutObjectRequest() | |
{ | |
BucketName = bucketName, | |
Key = keyName | |
}; | |
titledRequest.Metadata.Add("title", "the title"); | |
client.PutObject(titledRequest); | |
} | |
catch (AmazonS3Exception amazonS3Exception) | |
{ | |
if (amazonS3Exception.ErrorCode != null && | |
(amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || | |
amazonS3Exception.ErrorCode.Equals("InvalidSecurity"))) | |
{ | |
Console.WriteLine("Please check the provided AWS Credentials."); | |
Console.WriteLine("If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3"); | |
} | |
else | |
{ | |
Console.WriteLine("An error occurred with the message '{0}' when writing an object", amazonS3Exception.Message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment