How to upload a file to S3 without creating a temporary local file

前端 未结 10 1903
無奈伤痛
無奈伤痛 2021-01-30 13:49

Is there any feasible way to upload a file which is generated dynamically to amazon s3 directly without first create a local file and then upload to the s3 server? I use python.

10条回答
  •  清歌不尽
    2021-01-30 14:42

    Update for boto3:

    aws_session = boto3.Session('my_access_key_id', 'my_secret_access_key')
    s3 = aws_session.resource('s3')
    s3.Bucket('my_bucket').put_object(Key='file_name.txt', Body=my_file)
    

提交回复
热议问题