Upload resized image to S3

前端 未结 3 2026
失恋的感觉
失恋的感觉 2020-12-23 22:34

I\'m trying to upload resized image to S3:

fp = urllib.urlopen(\'http:/example.com/test.png\')
img = cStringIO.StringIO(fp.read())

im = Image.open(img)
im2          


        
3条回答
  •  孤城傲影
    2020-12-23 22:56

    print ("loading object", input_bucket, input_key)
    response = s3client.get_object(Bucket=input_bucket, Key=input_key)
    print("s3 get object response", response)
    
    body = response['Body']
    
    image = Image.open(body)
    
    print ("generating thumbnail", output_width, output_height)
    
    thumbnail = resizeimage.resize_thumbnail(
        image, [output_width, output_height])
    body.close()
    
    print ("saving thumbnail", output_format)
    
    with io.BytesIO() as output:
        thumbnail.save(output, output_format)
    
        print ("uploading thumbnail", output_bucket, output_key)
        output.seek(0)
        s3client.put_object(Bucket=output_bucket, Key=output_key,
                            Body=output, ContentType=output_content_type)
    

提交回复
热议问题