How can I use boto to stream a file out of Amazon S3 to Rackspace Cloudfiles?

后端 未结 5 1012
清歌不尽
清歌不尽 2020-11-30 00:14

I\'m copying a file from S3 to Cloudfiles, and I would like to avoid writing the file to disk. The Python-Cloudfiles library has an object.stream() call that looks to be wh

5条回答
  •  心在旅途
    2020-11-30 00:27

    Botocore's StreamingBody has an iter_lines() method:

    https://botocore.amazonaws.com/v1/documentation/api/latest/reference/response.html#botocore.response.StreamingBody.iter_lines

    So:

    import boto3
    s3r = boto3.resource('s3')
    iterator = s3r.Object(bucket, key).get()['Body'].iter_lines()
    
    for line in iterator:
        print(line)
    

提交回复
热议问题