我有一个无服务器应用程序,可以通过POST请求将文件上传到S3并通过GET请求提供服务。
我正在使用serverless-apigw-binary
和serverless-apigwy-binary
插件,以使我能够以图像形式返回二进制数据。为了让URL与浏览器一起工作,我必须将二进制类型设置为*/*
。
为了上传图片,POST端点需要像{ "base64": "..." }这样的主体。然而,在此配置中,整个主体都作为Base64编码的字符串传递。如何防止具有application/json
的请求正文被转换?
请参见下面的serverless.yml
:
service: image-service
custom:
envName: ${opt:stage, self:provider.stage}
domains:
prod: api.<mydomain>
dev: dev-api.<mydomain>
customDomain:
basePath: images
domainName: ${self:custom.domains.${self:custom.envName}}
certificateName: "*.<mydomain>"
apigwBinary:
types:
- '*/*'
provider:
name: aws
runtime: nodejs8.10
region: eu-west-1
memorySize: 1536
role: ImageRenderingRole
environment:
ENV_NAME: ${self:custom.envName}
APP_NAME: image-service
BUCKET: <mybucket>
plugins:
- serverless-offline
- serverless-domain-manager
- serverless-apigw-binary
- serverless-apigwy-binary
functions:
uploadImage:
handler: handler.uploadImage
events:
- http:
path: /
method: POST
getImage:
handler: handler.getImage
events:
- http:
path: 'images/{idAndFormat}'
method: get
contentHandling: CONVERT_TO_BINARY
parameters:
paths:
idAndFormat: true