Upload image available at public URL to S3 using boto

后端 未结 9 1291
广开言路
广开言路 2020-12-23 13:48

I\'m working in a Python web environment and I can simply upload a file from the filesystem to S3 using boto\'s key.set_contents_from_filename(path/to/file). However, I\'d l

9条回答
  •  我在风中等你
    2020-12-23 14:31

    I have tried as following with boto3 and it works me:

    import boto3;
    import contextlib;
    import requests;
    from io import BytesIO;
    
    s3 = boto3.resource('s3');
    s3Client = boto3.client('s3')
    for bucket in s3.buckets.all():
      print(bucket.name)
    
    
    url = "@resource url";
    with contextlib.closing(requests.get(url, stream=True, verify=False)) as response:
            # Set up file stream from response content.
            fp = BytesIO(response.content)
            # Upload data to S3
            s3Client.upload_fileobj(fp, 'aws-books', 'reviews_Electronics_5.json.gz')
    

提交回复
热议问题