这是我的Python Flask代码,它将文件上传到S3兼容存储中。 (它可以是AWS S3存储或Digital Ocean Space)
# This is Python Flask code, which will be hosted in Digital Ocean Droplet
@app.route('/', methods=['POST'])
def upload_file():
file = request.files['file']
# Is it possible to eliminate this step???
file.save('/tmp/file.ext')
session = boto3.session.Session()
client = session.client('s3',
region_name='nyc3',
endpoint_url='https://nyc3.digitaloceanspaces.com',
aws_access_key_id='ACCESS_KEY',
aws_secret_access_key='SECRET_KEY'
)
client.upload_file('/tmp/file.ext', # Path to local file
'my-space', # Name of Space
'file.ext') # Name for remote file
我的问题是,为了减少文件I / O操作,是否可以将file
对象直接传递给boto3
客户端,而不必使用{{1 }}?