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

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.