How to write a file or data to an S3 object using boto3

后端 未结 7 831
一生所求
一生所求 2020-11-28 21:21

In boto 2, you can write to an S3 object using these methods:

  • Key.set_contents_from_string()
  • Key.set_contents_from_file()
  • Key.set_contents_fr
7条回答
  •  迷失自我
    2020-11-28 21:55

    boto3 also has a method for uploading a file directly:

    s3 = boto3.resource('s3')    
    s3.Bucket('bucketname').upload_file('/local/file/here.txt','folder/sub/path/to/s3key')
    

    http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Bucket.upload_file

提交回复
热议问题