[英]ASP.NET Core ASW S3 - The request signature we calculated does not match the signature you provided
I am getting this error when I try to upload a file to the bucket.当我尝试将文件上传到存储桶时出现此错误。
This is my code.这是我的代码。
public async Task UploadFileAsync(IFormFile file, string userId)
{
var filePath = Path.GetFullPath(file.FileName);
var bucketName = this.configuration.GetSection("Amazon")["BucketName"];
var accessKey = this.configuration.GetSection("Amazon")["AWSAccessKey"];
var secretKey = this.configuration.GetSection("Amazon")["AWSSecretKey"];
var bucketRegion = RegionEndpoint.EUWest1;
var s3Client = new AmazonS3Client(accessKey, secretKey, bucketRegion);
try
{
var fileTransferUtility =
new TransferUtility(s3Client);
using (var newMemoryStream = new MemoryStream())
{
file.CopyTo(newMemoryStream);
var uploadRequest = new TransferUtilityUploadRequest
{
InputStream = newMemoryStream,
Key = file.FileName,
BucketName = bucketName,
CannedACL = S3CannedACL.PublicRead,
};
await fileTransferUtility.UploadAsync(uploadRequest);
}
await this.filesRepository.AddAsync(new FileBlob
{
Name = file.FileName,
Extension = file.FileName.Split('.')[1],
Size = file.Length,
UserId = userId,
UploadedOn = DateTime.UtcNow,
});
await this.filesRepository.SaveChangesAsync();
}
catch (AmazonS3Exception e)
{
Console.WriteLine(e.Message);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
It always says "The request signature we calculated does not match the signature you provided. Check your key and signing method."它总是说“我们计算的请求签名与您提供的签名不匹配。请检查您的密钥和签名方法。”
Any ideas?有任何想法吗?
The problem was the mistaken accessKey and secretKey.问题是错误的 accessKey 和 secretKey。 After I got them right all I had to do is change the CannedACL = S3CannedACL.BucketOwnerFullControl .
在我把它们做对之后,我所要做的就是改变CannedACL = S3CannedACL.BucketOwnerFullControl 。 That solved it for me
这为我解决了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.