我正在通过 lambda 将图像上传到 s3,一切正常,没有错误,但 API Gateway 的响应是 500 内部服务器错误。
我按照本教程配置了 api-gateway:对与 Amazon API Gateway 的 API 集成的二进制支持 https://aws.amazon.com/blogs/compute/binary-support-for-api-integrations-with-amazon-api-gateway/.
我的 lambda 接收 base64Image,对其进行解码并成功上传到 s3。
这是我的 lambda 代码:
def upload_image(event, context):
s3 = boto3.client('s3')
b64_image = event['base64Image']
image = base64.b64decode(b64_image)
try:
with io.BytesIO(image) as buffer_image:
buffer_image.seek(0)
s3.upload_fileobj(buffer_image, 'MY-BUCKET', 'image')
return {'status': True}
except ClientError as e:
return {'status': False, 'error': repr(e)}
这就是我收到的:
{
"message": "内部服务器错误"
},带有 500 状态代码。
Obs:我没有使用 lambda 代理集成。
您需要在响应中返回标头,例如在Python中:
return {
"statusCode": 200,
'headers': { 'Content-Type': 'application/json' },
"body": json.dumps(body)
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)