AWS上传 - 未找到存储桶

时间:2016-10-14 12:40:06

标签: c# amazon-web-services amazon-s3

我在app.config中有这个:

<div class="container">
<form class="form-inline" style="padding: 20px 0;">
    <div class="row">   
        <div class="col-sm-8 col-md-9">
            <div class="form-group">
                <label class="checkbox-inline"><input type="checkbox" value="">Option 1</label>
                <label class="checkbox-inline"><input type="checkbox" value="">Option 2</label>
            </div>
            <div class="form-group">
                <select class="form-control" id="sel1">
                    <option>Option 1</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                </select>
            </div>
            <div class="form-group">
                <input type="text" class="form-control" id="usr" placeholder="Placeholder">
            </div>
        </div>
        <div class="col-sm-4 col-md-3">
            <button type="button" class="btn btn-default">Default</button>
            <button type="button" class="btn btn-success">Success</button>
        </div>
    </div>
</form>

然后我尝试运行:

  <appSettings>
    <add key="AWSProfileName" value="myName"/>
    <add key="AWSRegion" value="eu-west-1" />
  </appSettings>

我在标记为“

”的行上有例外
  

输出&GT;&GT;

     

无法找到或打开PDB文件。抛出异常:   AWSSDK.dll中的'Amazon.S3.AmazonS3Exception'

     

AmazonS3exception未得到处理:

     

发生了“Amazon.S3.AmazonS3Exception”类型的未处理异常   在AWSSDK.dll中

     

附加信息:指定的存储桶不存在

我为using Amazon.S3; using Amazon.S3.Model; namespace createCSV { class S3 { public void uploadObject() { //IAmazonS3 client; string AwsAccessKey = "xxxxxxxxxxxxx"; string AwsSecretKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; IAmazonS3 client = new AmazonS3Client(AwsAccessKey,AwsSecretKey); PutObjectRequest request = new PutObjectRequest() { BucketName = @"http://s3-eu-west-1.amazonaws.com/bucketName/", Key = @"test/blah.txt", FilePath = @"P:\data_analysis\foo\blah.txt" }; PutObjectResponse response2 = client.PutObject(request); //<<exception here } } } 行尝试了很多不同的配置但仍有相同的例外 - 有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

BucketName的{​​{1}}参数应该是存储桶的名称(例如bucketName),而不是完全限定的端点(例如http://s3-eu-west-1.amazonaws.com/bucketName/)。您可以找到有关SDK here的更多信息。

答案 1 :(得分:1)

我想,你忘了在PutObjectRequest中插入BucketName属性。 请参阅下面的示例,将文件上传到AmazonS3。

        string secretKey = "your secret key";
        string accessKey = "your access key";
        AmazonS3Client client = new AmazonS3Client(secretKey, accessKey, RegionEndpoint.EUWest1);// choose your region endpoin for this example I am usgin eu-west-1
        PutObjectRequest uploadObjectRe = new PutObjectRequest()
        {
            BucketName = "qabucketireland",//your bucket name not full URL
            Key = "test/blah.txt",
            FilePath = @"c:\documents\script.txt"
        };
        client.PutObject(uploadObjectRe);

上传文件的另一种方法可以使用TransferUtility类,请参阅下面的示例:

            string secretKey = "your secret key";
            string accessKey = "your access Key";
            AmazonS3Client client = new AmazonS3Client(secretKey, accessKey, RegionEndpoint.EUWest1);
            TransferUtility transfer = new TransferUtility(client);
            transfer.Upload(@"c:\documents\script - Copy.txt", "qabucketireland", @"test/blah2.txt");

此外,您可以阅读此“How to upload a file to amazon S3 super easy using c#