在Amazon S3上上传图像.源代码

本文关键字:图像 源代码 S3 Amazon | 更新日期: 2023-09-27 17:49:18

我正在尝试在Amazon s3上上传图像。我尝试过不同的源代码,但没有白费。我坚持区分IAmazonClient, Amazons3对象等。谁能给我举个例子,指导我如何在s3上上传图像。我正在开发REST服务,可以捕获图像并在amazon s3上上传。

  • 我的桶在澳大利亚悉尼。
  • http://irisdb.s3apsoutheast2。amazonaws.com/
  • accesskey = "xxxxxxxx"
  • secretKey = "cxxxxxxxxx"
  • 端点: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();
    

我知道我需要提供amazon . endpoint。在serviceEndPoint中存在ap- southeastern -2,但在Amazon的定义中不存在"ap- southeastern -2"。端点请帮助

在Amazon S3上上传图像.源代码

最后我自己找到了解决办法。

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

使RegionalEndPoints正确我的应用程序运行得很好。谢谢大家。