Skip to content

Instantly share code, notes, and snippets.

@darko-mesaros
Created October 20, 2024 04:40
Show Gist options
  • Save darko-mesaros/46e54af19105869f92eae3b99af3fcab to your computer and use it in GitHub Desktop.
Save darko-mesaros/46e54af19105869f92eae3b99af3fcab to your computer and use it in GitHub Desktop.
import os
import boto3
s3_client = boto3.client('s3')
def upload_and_sign(file_path, bucket):
file_name = os.path.basename(file_path)
s3_client.upload_file(file_path, bucket, file_name)
url = s3_client.generate_presigned_url(
'get_object',
Params={
"Bucket": bucket,
"Key": file_name
},
ExpiresIn=3600)
return url
if __name__ == "__main__":
file_path = input("Enter file name to be uploaded: ")
bucket_name = input("Enter the name of he bucket to upload to: ")
url = upload_and_sign(file_path, bucket_name)
print(f"Here is your presigned URL: \n{url}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment