Amazon
Amazon copied to clipboard
Demo shows how to Put an Object to S3?
trafficstars
I wrote a demo to upload a file to S3 with the following codes, it always gets the following error: S3Exception: The request signature we calculated does not match the signature you provided. Check your key and signing method.
i have double-checked my access keys.
var cred = new Amazon.AwsCredential("xxxxx", "xxxxx");
var client = new Amazon.S3.S3Client(new Amazon.AwsRegion("ap-northeast-1"), cred);
var obj = new PutObjectRequest(client.Host, "backup", "/rewrite_amd64.msi");
obj.SetStorageClass(StorageClass.ReducedRedundancy);
var fs = new FileStream(@"C:\rewrite_amd64.msi", FileMode.Open);
obj.SetStream(fs, "application/octet-stream");
var mytask= client.PutObjectAsync(obj);
mytask.Wait();
Console.WriteLine(mytask.Result);
thank you.
Your example helped me, but make sure the arguments are correct. you have /rewrite_amd64.msi, which should be trimmed from slashes...
using var obj = new PutObjectRequest(_client.Host, builder.Host, $"{builder.Path.TrimStart('/')}/{fileName}");
obj.SetStorageClass(StorageClass.StandardInfrequentAccess);
using var sourceStream = File.OpenRead(source);
obj.SetStream(sourceStream, contentType);
var result = await _client.PutObjectAsync(obj, cancellationToken);