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 :
- Install AWS CLI and configure using aws configure
- 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 ?
精彩评论