Error/Wrong 在 AWS Lambda 上 python 中使用 pillow 包保存图像时的内容类型
Error/Wrong Content-Type while saving image using pillow package in python on AWS Lambda
我正在尝试使用 python 的枕头包生成立体图像。我面临的问题是 'Content-Type gets converting automatically to binary/octet-stream but my original image Content-Type is image/jpeg'
这是我用来生成缩略图的代码
def resize_image(image_path, resized_path, thumbnail_size):
with Image.open(image_path) as image:
image.thumbnail((thumbnail_size["x"], thumbnail_size["y"]))
image.save(resized_path,"JPEG",progressive=True)
终于找到解决办法了,问题是上传文件到s3时需要明确指定content-type。
s3_client.upload_file(upload_path, '{}'.format(bucket),
f'{filename}',ExtraArgs={'ContentType': '{}'.format(mimeType),'Metadata':{}})
我正在尝试使用 python 的枕头包生成立体图像。我面临的问题是 'Content-Type gets converting automatically to binary/octet-stream but my original image Content-Type is image/jpeg'
这是我用来生成缩略图的代码
def resize_image(image_path, resized_path, thumbnail_size):
with Image.open(image_path) as image:
image.thumbnail((thumbnail_size["x"], thumbnail_size["y"]))
image.save(resized_path,"JPEG",progressive=True)
终于找到解决办法了,问题是上传文件到s3时需要明确指定content-type。
s3_client.upload_file(upload_path, '{}'.format(bucket),
f'{filename}',ExtraArgs={'ContentType': '{}'.format(mimeType),'Metadata':{}})