下面的代码段可能有助于上传文件并生成类似于s3过期网址的快速共享网址。
#create boto client
client = session.client('s3',
region_name='nyc3',
endpoint_url='https://nyc3.digitaloceanspaces.com',
aws_access_key_id='xxxxxxxxxx',
aws_secret_access_key='xxxxxxxxxxxx',
config=Config(signature_version='s3'))
#upload file to spaces
client.upload_file('~/test.png', 'bucket_name', 'test.png')
#download file
url = client.generate_presigned_url(ClientMethod='get_object',
Params={'Bucket': 'bucket-name',
'Key': 'test.png'},
ExpiresIn=300)