我有一个无服务器应用程序,它将文件上传到 s3(通过 POST 请求)并为它们提供服务(通过 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