I’m generating a pre-signed-URL using the AWSSDK.S3 nuget from a .Net app using the code below.
var s3Client = new AmazonS3Client(<accessKeyId>, <secreAccessKey>, new AmazonS3Config
{
ServiceURL = <spacesEndpoint>
_});
var request = new GetPreSignedUrlRequest
{
BucketName = <bucketName>,
Key = <filePathKey>,
Expires = DateTime.UtcNow.AddMinutes(10),
ResponseHeaderOverrides = new ResponseHeaderOverrides
{
ContentDisposition = $"filename=\"{fileName}\"",
ContentType = <contentType>
}};
return _s3Client.GetPreSignedURL(request)
It works intermittently. In some cases, the generated URL is working and sometimes I get the error
<Error><Code>AuthorizationHeaderMalformed</Code><Message>The authorization header is malformed.</Message><Resource><do-space-file-path></Resource><RequestId>not available</RequestId></Error>
Has anyone encountered this before? Thanks!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there,
Indeed, as this is intermittent it can be quite tricky to troubleshoot. So what I could suggest here is:
If possible, configure your .NET app to generate detailed logs of the pre-signed URL generation process, including timestamps, headers, and the calculated signature. This can help pinpoint discrepancies.
Try to compare the working and failing requests. When you get a working URL and a failing URL, carefully compare their structures. Look for small differences in encoding, headers, or timestamps.
Try generating a pre-signed URL for the same object using the AWS CLI or another client. If this works, it can help eliminate bucket permission or endpoint configuration issues:
Let me know how it goes!
Best,
Bobby