Upload images on Amazon S3. source code

2019-09-10 12:52发布

问题:

I am trying to upload images on Amazon s3. I have tried different source codes but no vain.I am stuck to differentiate b/w IAmazonClient, Amazons3 objects etc. can anyone give me example and direct me how can i upload images on s3.I am developing REST service that can capture images and upload on amazon s3.

  • My bucket is in Sydney Australia.
  • http://irisdb.s3apsoutheast2. amazonaws.com/
  • accesskey = "xxxxxxxx"
  • secretKey = "cxxxxxxxxx"
  • Endpoint: irisdb.s3websiteapsoutheast2. amazonaws.com

        string accessKey = "xxxx";
        string secretKey = "mxxxxx";
        string bucketName = "irisdb"; // Set to a bucket you create              
        // Create S3 service client.            
    
        BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
        AmazonS3Config asConfig = new AmazonS3Config()
        {
            ServiceURL = "http://irisdb.s3-ap-southeast2.amazonaws.com/",
            ServiceEndPoint = "irisdb.s3-website-ap-southeast2.amazonaws.com" //error here (cannot convert string to endpoints)
        };
    
        AmazonS3Client client2 = new AmazonS3Client(awsCredentials, asConfig);
        ListBucketsResponse response = client2.ListBuckets();
    

I know i need to provide Amazon.Endpoints.ap-southeast-2 in serviceEndPoint but "ap-southeast-2" not exist in the definition of Amazon.EndPoint Please help

回答1:

Finally i find the solution by myself.

AmazonS3Config asConfig = new AmazonS3Config()
{
    ServiceURL = "http://irisdb.s3-ap-southeast2.amazonaws.com/",
    RegionEndpoint = Amazon.RegionEndpoint.APSoutheast2
};

Making RegionalEndPoints correct. my application run like a charm. Thanks for everyone.