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

前端 未结 10 1790
無奈伤痛
無奈伤痛 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:25

    The boto library's Key object has several methods you might be interested in:

    • send_file
    • set_contents_from_file
    • set_contents_from_string
    • set_contents_from_stream

    For an example of using set_contents_from_string, see Storing Data section of the boto documentation, pasted here for completeness:

    >>> from boto.s3.key import Key
    >>> k = Key(bucket)
    >>> k.key = 'foobar'
    >>> k.set_contents_from_string('This is a test of S3')
    

提交回复
热议问题