Skip to content

Instantly share code, notes, and snippets.

@brunomichetti
Last active July 12, 2022 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunomichetti/b2ab59783e013053b31136671aefb258 to your computer and use it in GitHub Desktop.
Save brunomichetti/b2ab59783e013053b31136671aefb258 to your computer and use it in GitHub Desktop.
def get_presigned_url_dict_to_upload_file(object_key: str) -> Dict[str, Any]:
'''
Returns a dict with the necessary data to upload a file for the given key
'''
session = Session(
aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
region_name=settings.AWS_S3_REGION_NAME,
)
s3client = session.client('s3')
url = s3client.generate_presigned_post(
Bucket=settings.AWS_STORAGE_BUCKET_NAME,
Key=object_key,
Fields={
'acl': 'private',
},
Conditions=[
{'acl': 'private'},
],
ExpiresIn=settings.AWS_PRESIGNED_URL_EXPIRATION_TIME_MINUTES,
)
return url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment