Can you upload to S3 using a stream rather than a local file?

前端 未结 5 1507
迷失自我
迷失自我 2020-11-29 23:17

I need to create a CSV and upload it to an S3 bucket. Since I\'m creating the file on the fly, it would be better if I could write it directly to S3 bucket as it is being cr

5条回答
  •  孤街浪徒
    2020-11-29 23:37

    According to docs it's possible

    s3.Object('mybucket', 'hello.txt').put(Body=open('/tmp/hello.txt', 'rb'))
    

    so we can use StringIO in ordinary way

    Update: smart_open lib from @inquiring minds answer is better solution

提交回复
热议问题