Created
December 17, 2023 15:16
-
-
Save milisarge/85877f0c5a892a13259cf2e52b697445 to your computer and use it in GitHub Desktop.
Filebase upload file
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
#!/bin/env python3 | |
import boto3 | |
import requests | |
import json | |
import os | |
import sys | |
from botocore.config import Config | |
s3 = boto3.client('s3') | |
boto_config = Config( | |
region_name = 'us-east-1', | |
signature_version = 's3v4') | |
s3 = boto3.client( | |
's3', | |
endpoint_url = 'https://s3.filebase.com', | |
aws_access_key_id='KEY', | |
aws_secret_access_key='SECRET', | |
config=boto_config) | |
bucket = "BUCKET" | |
file_path = sys.argv[1] | |
print(file_path) | |
file_name = os.path.basename(file_path) | |
file_name = file_name.split("-x86_64")[0] | |
print (" Generating pre-signed url...") | |
response = s3.generate_presigned_url('put_object', Params={'Bucket':bucket,'Key':file_name}, ExpiresIn=3600, HttpMethod='PUT') | |
print(response) | |
if response is None: | |
exit(1) | |
else: | |
cmd = 'curl -X PUT -T {} "{}"'.format(file_path, response) | |
print(cmd) | |
os.system(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
need to install boto3 with pip3