[英]Can I upload form-data files to S3 via AWS API-Gateway?
In AWS environment I want to upload a file to S3 via API gateway.在 AWS 环境中,我想通过 API 网关将文件上传到 S3。 I can't use lambda, because the 6MB payload limit.
我不能使用 lambda,因为 6MB 有效负载限制。 (The API gateway's 10MB limit is fine.) I could manage to upload a file with POST request and binary body.
(API 网关的 10MB 限制很好。)我可以设法上传一个带有 POST 请求和二进制正文的文件。 My question is how can I upload a picture which is wrapped in a multipart/form-data and can I set a file size and format limitation without using lambda functions?
我的问题是如何上传包含在 multipart/form-data 中的图片,并且可以在不使用 lambda 函数的情况下设置文件大小和格式限制吗?
You should use aws-sdk to create the API end point and get the url:您应该使用 aws-sdk 创建 API 端点并获取 url:
API Code(aws-sdk API Doc) : API 代码(aws-sdk API 文档) :
s3.getSignedUrl('putObject')
s3.getSignedUrl('putObject')
S3.putObject
for upload document, it is a difference conceptS3.putObject
上传文件,这是一个不同的概念 return new Promise((resolve, reject) => { let url = this.S3.getSignedUrl("getObject", { Bucket: bucket, Key: key, Expires: expires_second }) return resolve(url)
S3 Bucket Config (Reference Link) : S3 存储桶配置(参考链接) :
[ { "AllowedHeaders": [ "*", "Authorization" ], "AllowedMethods": [ "POST", "GET", "PUT", "DELETE", "HEAD" ], "AllowedOrigins": [ "*" ], "ExposeHeaders": [], "MaxAgeSeconds": 3000 } ]
AllowedMethods
existing PUT
methodAllowedMethods
现有PUT
方法Upload Document(Postman case)上传文件(邮递员案例)
s3.getSignedUrl('putObject')
s3.getSignedUrl('putObject')
获取的链接{ Accept: '*/*'}
{ Accept: '*/*'}
{Accept: 'image/png' }
{Accept: 'image/png' }
now you may check the s3 bucket现在您可以检查 s3 存储桶
other helpful reference : https://medium.com/@aidan.hallett/securing-aws-s3-uploads-using-presigned-urls-aa821c13ae8d其他有用的参考: https ://medium.com/@aidan.hallett/securing-aws-s3-uploads-using-presigned-urls-aa821c13ae8d
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.