Question

Intermittent error AuthorizationHeaderMalformed when requesting for presigned url for viewing the file

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!


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
April 15, 2024

Hi there,

Indeed, as this is intermittent it can be quite tricky to troubleshoot. So what I could suggest here is:

  1. 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.

  2. 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.

  3. 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:

https://docs.digitalocean.com/glossary/pre-signed-url/

Let me know how it goes!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel