1

I have this in app.config:

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

Then I try to run this:

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
  }

  }
}

I get an exception on the line marked saying:

Output>>

Cannot find or open the PDB file. Exception thrown: 'Amazon.S3.AmazonS3Exception' in AWSSDK.dll

AmazonS3exception was unhandled:

An unhandled exception of type 'Amazon.S3.AmazonS3Exception' occurred in AWSSDK.dll

Additional information: The specified bucket does not exist

I've tried lots of different configurations for the line BucketName = @"http://s3-eu-west-1.amazonaws.com/bucketName/" with still the same exception - can anyone help?

whytheq
  • 34,466
  • 65
  • 172
  • 267
  • 1
    check url correct or not. – Vivek Nuna Oct 14 '16 at 12:42
  • @viveknuna if i add the url to the browser it does not give 404 but goes to a page saying access denied which seems good? – whytheq Oct 14 '16 at 12:47
  • invalidate your resource and then try. – Vivek Nuna Oct 14 '16 at 12:50
  • Use lower-case bucket names. [Bucket restrictions](http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html) has an example of this exact error condition when using a bucket named MyAWSBucket which resolves to myawsbucket and ends up with a bucket not found error. – leetibbett Oct 14 '16 at 12:50
  • Shouldn't bucket name be of the `s3://s3-eu-west...` form? – hjpotter92 Oct 14 '16 at 13:06
  • Or maybe simply `bucketName` as seen on https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/S3/TS3PutObjectRequest.html – hjpotter92 Oct 14 '16 at 13:08
  • 2
    As shown here (http://docs.aws.amazon.com/sdkfornet/v3/apidocs/Index.html) the BucketName should be just the name of the bucket not the entire URL. You can specify the service endpoint when you create the AmazonS3Client object. – garnaat Oct 14 '16 at 13:26
  • @garnaat you can add an answer if you like - as your comment is the answer! – whytheq Oct 14 '16 at 13:52

2 Answers2

1

The BucketName parameter to PutObjectRequest should be the name of the bucket (e.g. bucketName) rather than the fully qualified endpoint (e.g. http://s3-eu-west-1.amazonaws.com/bucketName/). You can find more info about the SDK here.

garnaat
  • 44,310
  • 7
  • 123
  • 103
1

I think,You forgot insert BucketName property in the PutObjectRequest. see the example below to upload a file to 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);

Another way to upload a file Could be using TransferUtility class see the example below:

            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");

Also You could read this "How to upload a file to amazon S3 super easy using c#"

Community
  • 1
  • 1