简体   繁体   English

在 AWS Lambda 上的 python 中使用枕头 package 保存图像时出现错误/错误的内容类型

[英]Error/Wrong Content-Type while saving image using pillow package in python on AWS Lambda

I'm trying to generate dimensional images using a pillow package using python. The problem I'm facing is 'Content-Type gets converting automatically to binary/octet-stream but my original image Content-Type is image/jpeg '我正在尝试使用枕头 package 使用 python 生成立体图像。我面临的问题是“内容类型自动转换为二进制/八位字节流,但我的原始图像内容类型是图像/jpeg

Here is code which I'm using to generate thumbnails这是我用来生成缩略图的代码

 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)

Finally found the solution, problem is while uploading the file to s3 you need to specify the content-type explictly.终于找到了解决方案,问题是将文件上传到 s3 时需要明确指定内容类型。

s3_client.upload_file(upload_path, '{}'.format(bucket),
                      f'{filename}',ExtraArgs={'ContentType': '{}'.format(mimeType),'Metadata':{}})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 GCS 生成具有内容类型配置的预签名 URL Ruby SDK - How to generate a presigned URL with content-type disposition using GCS Ruby SDK 尝试使用 node.js Lambda 函数在 AWS REST API 配置上使用 Axios 发布数据时出现 CORS 错误 - CORS error while trying to post data with Axios on AWS REST API configuration using a node.js Lambda function 请求的资源上不存在“Access-Control-Allow-Origin”header。 使用 aws lambda 将图像上传到 s3 - no 'Access-Control-Allow-Origin' header is present on the requested resource. while uploading image to s3 using aws lambda Bazel 使用 python 生成 AWS lambda - Bazel generate AWS lambda with python 如何将 package AWS CDK 转化为 Lambda 层? - How to package AWS CDK into Lambda layer? 如何在 AWS Lambda 中将消息记录到错误日志中的 Python - How to log messages to error log in Python in AWS Lambda 将 aws lambda 与 redis 连接时,任务在 23.02 秒错误后超时 - while connecting aws lambda with redis getting Task timed out after 23.02 seconds error 在 aws Lambda 上安装 \"sharp\" 时出错 - Something went wrong installing the \"sharp\" on aws Lambda aws cloudformation lambda python 错误处理程序 - aws cloudformation lambda python bad handler 如何使用 AWS Lambda [NodeJS] 将 base64 编码字符串作为图像上传到 S3 - How to upload a base64 encoding string as an image to S3 using AWS Lambda [NodeJS]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM