private static AmazonS3Client GetS3Client()
{
var credentials = new BasicAWSCredentials(accessKey, secretKey);
return new AmazonS3Client(credentials, new AmazonS3Config
{
ServiceURL = "xxxx",
});
}
public static string GeneratePreSignedUrl(string fileName, TimeSpan expiry, string bucketName)
{
using (AmazonS3Client client = GetS3Client())
{
var request = new GetPreSignedUrlRequest
{
BucketName = bucketName,
Key = fileName,
Verb = HttpVerb.GET,
Expires = DateTime.UtcNow.Add(expiry),
};
return client.GetPreSignedURL(request);
}
}
如果我使用AWS S3(没有ServiceUrl)加载图像URL,则毫无问题地工作,并且在浏览器中可见图像。但是,如果我使用CloudFlare R2,则访问生成的URL显示以下内容:
GeneratePreSignedUrl
我不知道这个消息的含义。但是,here
它说不支持SIGV4?,我还检查了
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>Unauthorized</Code>
<Message>SigV2 authorization is not supported. Please use SigV4 instead.</Message>
</Error>
方法是否有效,所以我似乎无法使用R2使用AWS SDK,但是GetObjectAsync
不起作用。
我该怎么办?谢谢
尝试生成预先签名的URL时,观察到相同的“未经授权”错误,即使我能够成功地将文件上传到R2存储中。
文献表明您必须将
GetPreSignedURL
设置为AWSConfigsS3.UseSignatureVersion4