question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using headers in presigned urls

See original GitHub issue

Hi guys!

I’m changing from boto2 and I’ve stopped in generation of presigned urls. With boto2 we can give headers to generate presigned urls, but with boto3 I didn’t found this option. I need to give a Content-Type header to upload a video with correct content type.

My actual code with boto2:

s3 = boto.connect_s3()
headers = [{'Content-Type': 'image/jpeg'}]
return s3.generate_url(7200, 'PUT', 'my-bucket', 'my-key', headers)

Am I missing something? There is a way to give headers to generate_presigned_url?

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
kyleknapcommented, Apr 11, 2016

So there is no parameter for custom headers in boto3’s generate_presigned_url. The headers get added based on the parameters that you would normally pass to the client’s method. So something like this:

import boto3

s3 = boto3.client('s3')

# Generate the URL to get 'key-name' from 'bucket-name'
url = s3.generate_presigned_url(
    ClientMethod='put_object',
    Params={
        'Bucket': 'bucket-name',
        'Key': 'key-name',
        'ContentType': 'image/jpeg'
    }
)
print(url)

Hopes this helps.

1reaction
random1stcommented, Apr 27, 2016

Full situation. I create request to service with Content-Type header. After I redirect request to AWS S3 service(302 Redirect). And S3 check request and raise “SignatureDoesNotMatch” exception. With url, generated with old boto, all work correct. I created new issue https://github.com/boto/boto3/issues/610

Read more comments on GitHub >

github_iconTop Results From Across the Web

s3 presigned url mandatory custom request headers
I am trying to generate a presigned url with some user data along with, as I understand I need to use custom request...
Read more >
Using headers in presigned urls for S3 "get_object" methods.
I tried to append headers manually (create request_dict, add headers, call get_presigned_url method of requestsigner), but url is invalid. Now I ...
Read more >
Creating Pre-Signed URLs for Amazon S3 Buckets
A pre-signed URL allows you to grant temporary access to users who don't have permission to directly run AWS operations in your account....
Read more >
Dynamically set content-type headers for S3 presigned urls ...
Share All sharing options for: Dev tip: How to dynamically set content-type headers for S3 presigned urls with a native fetch request ·...
Read more >
Securing your Amazon AWS S3 presigned URLs, tips and tricks
8. Using signed headers, you can add a file's hash and avoid uncontrolled file uploads ... As said before, once a presigned URL...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found