Created
October 20, 2024 04:40
-
-
Save darko-mesaros/46e54af19105869f92eae3b99af3fcab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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