在AWS Lambda上使用python中的pillow包保存图像时出错/内容类型错误
我正在尝试使用python的枕头包生成三维图像。我面临的问题是“内容类型自动转换为二进制/八位字节流,但我原来的图像内容类型是图像/jpeg” 下面是我用来生成缩略图的代码在AWS Lambda上使用python中的pillow包保存图像时出错/内容类型错误,python,image-processing,aws-lambda,python-imaging-library,mime-types,Python,Image Processing,Aws Lambda,Python Imaging Library,Mime Types,我正在尝试使用python的枕头包生成三维图像。我面临的问题是“内容类型自动转换为二进制/八位字节流,但我原来的图像内容类型是图像/jpeg” 下面是我用来生成缩略图的代码 def resize_image(image_path, resized_path, thumbnail_size): with Image.open(image_path) as image: image.thumbnail((thumbnail_size["x"], thumbnail_size
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时,您需要明确指定内容类型
s3_client.upload_file(upload_path, '{}'.format(bucket),
f'{filename}',ExtraArgs={'ContentType': '{}'.format(mimeType),'Metadata':{}})