Reputation: 35605
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?
Upvotes: 1
Views: 2208
Reputation: 1140
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#"
Upvotes: 1
Reputation: 45916
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.
Upvotes: 1