无服务器I映像上载到S3后在部署后损坏

无服务器I映像上载到S3后在部署后损坏

本文介绍了无服务器I映像上载到S3后在部署后损坏,仅本地有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用serverless和NodeJS将图像上传到S3,但是上传后出了点问题.在本地使用serverless-offline时,一切都像冠军一样工作,但是在部署后出现此错误.然后,我尝试拦截并检测发生了什么,并看到以下结果:

I trying to upload an image to S3 uses serverless and NodeJS but something wrong after upload. In local uses serverless-offline everything worked like champ but after deploy I got this error. Then I tried to intercept and detect what's happened and see this result:

图像主体中出现了一些奇怪的字符,例如<0x0a> 0x01 0x04

Some strange character appeared in image body such as <0x0a> 0x01 0x04

我也尝试使用serverless-apigw-binary,但是没有运气.

I also tried to use serverless-apigw-binary but not luck.

推荐答案

以下方法对我有用.

如果要通过lambda上传文件,一种方法是打开您的AWS API Gateway控制台.

If want to upload file through lambda, one way is to open your AWS API Gateway console.

转到

"API" -> {YourAPI}-> 设置"

"API" -> {YourAPI} -> "Settings"

您将在其中找到二进制媒体类型";部分.

There you will find "Binary Media Types" section.

添加以下媒体类型:

保存您的更改.

然后转到资源" -> 代理方法"(例如"ANY")- 方法请求" -> "HTTP请求标头"并添加以下标头"Content-Type","Accept".

Then Go to "Resources" -> "proxy method"(eg. "ANY") -> "Method Request" -> "HTTP Request Headers" and add following headers "Content-Type", "Accept".

最后部署您的api.

有关更多信息,请访问: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings-configure-with-console.html

For more info visit: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings-configure-with-console.html

这篇关于无服务器I映像上载到S3后在部署后损坏,仅本地有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 03:10