Created
July 7, 2021 09:50
-
-
Save squeaky-pl/207430b9207de2013d792540a827a2e2 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
In [32]: s3_url = "s3://<access key id>:<secret access key>@oss-eu-central-1.aliyuncs.com/<bucket name>" | |
In [33]: parsed_s3_url = urllib.parse.urlparse(s3_url) | |
In [34]: session = boto3.Session(aws_access_key_id=parsed_s3_url.username,aws_secret_access_key=parsed_s3_url.password) | |
In [35]: s3_config = botocore.config.Config(signature_version="s3v4", s3={"addressing_style": "virtual"}) | |
In [36]: client = session.client("s3", endpoint_url=f"https://{parsed_s3_url.hostname}", config=s3_config) | |
In [37]: # actual upload | |
In [38]: response = client.put_object(Key="filename", ACL="public-read", Body=b"bytes_bytes", Bucket=parsed_s3_url.path[1:]) | |
In [39]: # get download url | |
In [40]: location = f"https://{parsed_s3_url.path[1:]}.{parsed_s3_url.hostname}/filename" | |
In [41]: location | |
Out[41]: 'https://<bucket_name>.oss-eu-central-1.aliyuncs.com/filename' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment