Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S3 and .net Amazon SDK - GetObject is inaccessible due to protection level

I am trying to download a file from S3 to a byte array iin .net using c#.

I am following the below method:

var client = new AmazonS3Client(AccessKey, SecretKey, Amazon.RegionEndpoint.EUWEST2);
    using (client)
    {
        MemoryStream ms = new MemoryStream();
        GetObjectRequest getObjectRequest = new GetObjectRequest();
        getObjectRequest.BucketName = Bucketname;
        getObjectRequest.Key = Keyname;

        using (var getObjectResponse = client.GetObject(getObjectRequest))
        {
            getObjectResponse.ResponseStream.CopyTo(ms);
        }
 }
 

I referred to a stackoverflow answer and followed the above method.

However I am getting the following error saying;

GetObject is inaccessible due to protection level.

I am just learning S3, I am now confused if this error is because of bucket policy or class scope.

like image 212
Abhilash Gopalakrishna Avatar asked Nov 26 '18 10:11

Abhilash Gopalakrishna


1 Answers

You mention .NET Core: most of the AWS APIs for .Net Core and .NET Standard only provide Async variants. You should use GetObjectAsync.

It's surprising that Amazon introduced this incompatibility as it would have been easy to provide a synchronous version, using code something like:

var task = s3Client.GetObjectAsync(request);
task.Wait();
return task.Result;
like image 112
Joe Avatar answered Sep 27 '22 22:09

Joe