Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo shows how to Put an Object to S3? #6

Open
mirror222 opened this issue Mar 24, 2020 · 1 comment
Open

Demo shows how to Put an Object to S3? #6

mirror222 opened this issue Mar 24, 2020 · 1 comment

Comments

@mirror222
Copy link

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.

@egbertn
Copy link

egbertn commented Nov 10, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants