イメージをs3から取得し、それを量子化/操作してから、ディスクに何も保存せずにs3に保存しますメモリ)。私は一度それをすることができましたが、コードに戻って再び試してみるとうまくいかなかったのです。コードは以下の通りである:私が受け取ったイメージをバイトに保存し、コンテンツを返すboto3にアップロードする-MD5不一致
import boto3
import io
from PIL import Image
client = boto3.client('s3',aws_access_key_id='',
aws_secret_access_key='')
cur_image = client.get_object(Bucket='mybucket',Key='2016-03-19 19.15.40.jpg')['Body'].read()
loaded_image = Image.open(io.BytesIO(cur_image))
quantized_image = loaded_image.quantize(colors=50)
saved_quantized_image = io.BytesIO()
quantized_image.save(saved_quantized_image,'PNG')
client.put_object(ACL='public-read',Body=saved_quantized_image,Key='testimage.png',Bucket='mybucket')
エラーは次のとおりです。
botocore.exceptions.ClientError: An error occurred (BadDigest) when calling the PutObject operation: The Content-MD5 you specified did not match what we received.
私はちょうど画像を引っ張って、それを操作することなくすぐに戻ってそれを置く場合、それは正常に動作します。私はここで何が起こっているのかよく分かりません。
put_object()Body expect:ボディ(バイトまたはシーク可能なファイルライクなオブジェクト) - オブジェクトデータ。 put_object()の前にsaved_quantized_image.seek(0)を試すことができますか? – mootmoot