Amazon AWS S3 browser-based upload using POST -

后端 未结 3 1868
面向向阳花
面向向阳花 2020-12-17 17:32

I am building a web application that includes a file upload feature. My goal is to initiate upload from users directly to an S3 bucket. The strategy is to pre-sign a POST re

3条回答
  •  一生所求
    2020-12-17 17:40

    Found a solution: had to explicitly configure the s3 client to use Amazon's new signature v4. The error occurs since it defaults to an older version, causing the mismatch. Bit of a facepalm - at the time this wasn't written in boto3 docs, although folks at Amazon say it should be soon.

    The method is simplified since it now returns exactly the fields required:

    def s3_upload_creds(name):
        BUCKET = 'mybucket'
        REGION = 'us-west-1'
        s3 = boto3.client('s3', region_name=REGION, config=Config(signature_version='s3v4'))
        key = '${filename}'
        return s3.generate_presigned_post(
            Bucket = BUCKET,
            Key = key
        )
    

    Which means the form can be easily generated:

    
      
        
      
      
        {{ creds }}
          
    {% for key, value in creds.fields.items() %} {% endfor %} File:

    Cheers

提交回复
热议问题