Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found the issue, at last.</p> <p>When targeting buckets in a specific region, the Amazon S3 client object will have to be configured to use a specific endpoint. The code to configure the endpoint is as in the constructor and creation of the client is in the individual methods of the class below:</p> <pre><code>public class AmazonS3Service : IAmazonS3Service { private AmazonS3 client; private string accessKeyID; private string secretAccessKeyID; private AmazonS3Config config; public AmazonS3Service() { accessKeyID = ConfigurationManager.AppSettings["AWSAccessKey"]; secretAccessKeyID = ConfigurationManager.AppSettings["AWSSecretKey"]; config = new AmazonS3Config(); config.ServiceURL = ConfigurationManager.AppSettings["AWSEUEndPoint"]; } public void CreateBucket(string bucketName) { using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID, config)) { try { PutBucketRequest request = new PutBucketRequest(); request.WithBucketName(bucketName) .WithBucketRegion(S3Region.EU); client.PutBucket(request); } catch (AmazonS3Exception amazonS3Exception) { if (amazonS3Exception.ErrorCode != null &amp;&amp; (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity"))) { //log exception - ("Please check the provided AWS Credentials."); } else { //log exception - ("An Error, number {0}, occurred when creating a bucket with the message '{1}", amazonS3Exception.ErrorCode, amazonS3Exception.Message); } } } } public void UploadFile(string bucketName, Stream uploadFileStream, string remoteFileName) { using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID, config)) { try { PutObjectRequest request = new PutObjectRequest(); request.WithBucketName(bucketName) .WithCannedACL(S3CannedACL.PublicRead) .WithKey(remoteFileName) .WithInputStream(uploadFileStream); using (S3Response response = client.PutObject(request)) { WebHeaderCollection headers = response.Headers; foreach (string key in headers.Keys) { //log headers ("Response Header: {0}, Value: {1}", key, headers.Get(key)); } } } catch (AmazonS3Exception amazonS3Exception) { if (amazonS3Exception.ErrorCode != null &amp;&amp; (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity"))) { //log exception - ("Please check the provided AWS Credentials."); } else { //log exception -("An error occurred with the message '{0}' when writing an object", amazonS3Exception.Message); } } } } } </code></pre> <p>The various endpoints of each of Amazon's services can be found at at this URL - <a href="http://docs.amazonwebservices.com/general/latest/gr/index.html?rande.html" rel="noreferrer">http://docs.amazonwebservices.com/general/latest/gr/index.html?rande.html</a></p> <p>Hope this helps someone!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload