English 中文(简体)
在亚马孙S3区将档案上载到一个桶,没有“达到的工业尝试数量”
原标题:Uploading a file to a bucket in Amazon S3 failing with "Maximum number of retry attempts reached"

I have been trying to create buckets and upload files to Amazon S3 using their .net SDK. I am able to create the buckets and specify that they be created in the EU region. The code used to create the buckets is as below

PutBucketRequest request = new PutBucketRequest();
request.WithBucketName(bucketName)
       .WithBucketRegion(S3Region.EU);

client.PutBucket(request);

接着,我着手用以下代码将文件上载到桶子:

PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(bucketName)
    .WithCannedACL(S3CannedACL.PublicRead)
    .WithKey(remoteFileName)
    .WithInputStream(uploadFileStream);

文档上载代码的错误是“接触到的中度再造尝试”

Can anyone let me know what else I need to be doing in order for the upload to work?

感谢。

http://www.un.org。 利用AWS Management Console公司将档案上载到同一桶,将罚款。

问题回答

最后,我发现这个问题。

在某个特定区域瞄准桶时,亚马孙S3客户目标必须加以配置,以使用特定终点。 规定最终点的法典与客户的构造和创建一样,采用以下类别的个人方法:

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 && (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 && (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);
                }
            }
        }
    }
 }

亚马孙各服务部门的各端点可在以下网址查阅:http://docs.amazonwebservices.com/general/latest/gr/index.html?rande.html“rel=”http://docs.amazonwebservices.com/general/latest/gr/index.html?rande.html

希望能帮助人们!





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签