Search code examples
pythondjangobotopre-signed-urls3-bucket

How to upload video on S3 bucket using signed URL created by Python Boto v2.38.0?


we have one functionality where we need to create an s3 bucket signed URL for the client. the client will upload a video on that URL.

we are using Boto version 2.38.0 for generating signed URL.

conn = boto.connect_s3()
key = "test_key"
bucket = "test_bucket"

signed_url = conn.generate_url(
    expires_in=600,
    method="PUT",
    bucket=bucket,
    key=key,
    headers={'Content-Type': 'application/octet-stream'}
)

I can upload the file with binary, but I can not upload the file with form-data. I have also tried multipart/form-data for the same. So, Could you please suggest me some request with signed URL video upload using POSTMAN?

Any help would be highly appreciated.

Thanks.


Solution

  • You can use boto's build_post_form_args to obtain the HTML form data necessary to do a signed post request:

    conn = connection.S3Connection(
        aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
        aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
    )
    
    data = conn.build_post_form_args(
        bucket_name=bucket_name,
        acl='public-read',
        storage_class=None,
        http_method="https",
    )
    

    You will get a dictionary containing form field names and values as well as a url to POST to.