Cloudflare R2 R2预先签名的URL生成 我有以下代码(与此文档页面几乎相同): 私有静态Amazons3Client get3Client() { var凭据= new BasicAwsCredentials(AccessKey,SecretKey); 返回新

问题描述 投票:0回答:1
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

以明确启用签名版本4。在我的情况下,这似乎不够
.net amazon-s3 cloudflare aws-sdk-net cloudflare-r2
1个回答
0
投票
。没有后者,它会失败,而“ signaturedoesnotmatch”错误。

样本代码如下:

request.ResponseHeaderOverrides.ContentType


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.