开发者

Not Able to Upload File on Amazon S3 using Stream

I am getting the below exception while uploading file to S3 AWS using DOT net core

{"Error making request with Error Code Forbidden and Http Status Code Forbidden. No further error information was returned by the service."}

I tried all these things to debug this :

  1. Install AWS CLI and configure using aws configure
  2. Added permission as AmazonS3FullAccess to user.

Code :

 var clientq = new Amazon.S3.AmazonS3Client(AccessKey, SecretKey, RegionEndpoint.APSouth1);
                var doesS3BucketExist = await AmazonS3Util.DoesS3BucketExistV2Async(clientq, BucketName);

                byte[] f开发者_开发知识库ileByte = new Byte[file.Length];
                file.OpenReadStream().Read(fileByte, 0, Int32.Parse(file.Length.ToString()));

                if (doesS3BucketExist)
                {


                    using (var stream = new MemoryStream(fileByte))
                    {
                        var request = new PutObjectRequest
                        {
                            BucketName = BucketName,
                            Key = file.FileName,
                            InputStream = stream,
                            ContentType = file.ContentType
                        };
                        // specify no ACL, else upload will be blocked by S3!
                       var response = await clientq.PutObjectAsync(request);
                    }

                    return true;
                }

Also, i have observed when i am using InputStream = stream, then i am getting this exception.

Can anyone help me on this ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜