使用.NET S3 API上传Base64图片至Cloudflare R2时遭遇STREAMING-AWS4-HMAC-SHA256-PAYLOAD未实现错误的问题求助
.NET S3 API上传Base64图片至Cloudflare R2时遭遇STREAMING-AWS4-HMAC-SHA256-PAYLOAD未实现错误的问题求助
大家好,我最近在做一个功能:用Angular网站上传图片,然后把图片传到我的.NET REST API,再通过S3兼容的API把Base64格式的图片上传到Cloudflare R2。但是现在遇到了一个错误,折腾了好久都没解决,想请教下各位大佬。
先给大家看看我的.NET API代码:
[Route("api/[controller]")] [Authorize] [ApiController] public class FileController : ControllerBase { private static IAmazonS3 s3Client; public FileController() { string accesKey = <<accesKey>>; string secretKey = <<secretKey>>; BasicAWSCredentials credentials = new BasicAWSCredentials(accesKey, secretKey); s3Client = new AmazonS3Client(credentials, new AmazonS3Config { ServiceURL = <<serviceURL>>, }); } [HttpPost("{fileName}")] [AllowAnonymous] public string uploadFile(string fileName, base64ImageDTO base64Image) { try { byte[] bytes = Convert.FromBase64String(base64Image.base64String); using (s3Client) { var request = new PutObjectRequest { BucketName = <<bucketName>>, CannedACL = S3CannedACL.PublicRead, Key = fileName, }; using (var ms = new MemoryStream(bytes)) { request.InputStream = ms; var response = s3Client.PutObjectAsync(request); } } } catch(Exception ex) { Console.WriteLine("aws fail"); } return ""; } }
运行后抛出的错误信息是这样的:
Amazon.S3.AmazonS3Exception: STREAMING-AWS4-HMAC-SHA256-PAYLOAD not implemented ---> Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown. at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken) at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.RedirectHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext) at Amazon.S3.Internal.AmazonS3ResponseHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
我排查了好一会儿,还是没找到问题所在,有没有人能帮我看看哪里出错了?
备注:内容来源于stack exchange,提问作者Olivier De Brabant
相关产品推荐
相关产品推荐

