简体   繁体   English

通过托管在 ElasticBeansStalk 上的 API 网关在 AWS S3 上上传图像

[英]Upload image on AWS S3 through API Gateway hosted on ElasticBeansStalk

I have deployed a REST API on elasticbeanstalk, which uploads the image on s3 bucket.我在 elasticbeanstalk 上部署了一个 REST API,它将图像上传到 s3 存储桶上。

REST API is written in node.js and front end is in Reactjs. REST API写在node.js,前端在Reactjs。

When I called the REST API hosted on elasticbeanstalk, which can upload the file on s3.当我调用 REST API 托管在 elasticbeanstalk 上时,它可以在 s3 上上传文件。 After uploading, the file is accessible and displayed correctly.上传后,文件可访问并正确显示。

I have also deployed the REST API on my local host, and upload the file.我还在本地主机上部署了 REST API,并上传了文件。 It is working fine.它工作正常。 The uploaded file is displayed correctly.上传的文件显示正确。

Alternatively, I have configured API gateway with elasticbeanstalk too.或者,我也使用 elasticbeanstalk 配置了 API 网关。 When I called the same REST API via API gateway and which can upload the file on s3.当我通过 API 网关调用相同的 REST API 并且可以在 s3 上上传文件时。 After the uploading, the file is available on the bucket but somehow that file is not opened correctly.上传后,该文件在存储桶中可用,但不知何故无法正确打开该文件。 The file seems corrupt.该文件似乎已损坏。 It may be an issue with the access policy.这可能是访问策略的问题。

I also see this issue on the file on one occasion我也曾在文件中看到过这个问题

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>10292CE4C4D62A301</RequestId>
<HostId>XJjQBB3DwB6H0lVkS5cHpj3D9ysTa9tApFaacsklg6MGFEnRwyRWLgnVojM8jY3TpCZ6/NQfMogg=</HostId>
</Error>

This is the file which is displayed correctly.这是正确显示的文件。 It is uploaded by calling the REST API directly from local host or elastic beanstalk.它是通过直接从本地主机或弹性 beantalk 调用 REST API 上传的。 https://images-for-naradej.s3.amazonaws.com/2021-01-14T23%3A39%3A49.938Z-largebanner.jpg https://images-for-naradej.s3.amazonaws.com/2021-01-14T23%3A39%3A49.938Z-largebanner.jpg

this is the file which is not displayed.这是未显示的文件。 It is uploaded by calling the API Gateway connected to Elastic beanstalk.通过调用连接Elastic beanstalk的API Gateway上传。 https://images-for-naradej.s3.amazonaws.com/2021-01-14T23%3A46%3A23.030Z-largebanner.jpg https://images-for-naradej.s3.amazonaws.com/2021-01-14T23%3A46%3A23.030Z-largebanner.jpg

I am not sure why the file is corrupted or access denied when I upload it via API gateway.我不确定为什么当我通过 API 网关上传文件时文件损坏或访问被拒绝。

Can somebody help me with that?有人可以帮我吗?

This issue is fixed by adding the binary media types in api gateway.通过在 api 网关中添加二进制媒体类型来解决此问题。 The type should be "multipart/form-data"类型应该是“multipart/form-data”

添加二进制媒体类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Node.js 中使用 lambda API 网关在 s3 中上传图像(aws-lambda-multipart-parser) - Image Upload in s3 using lambda API gateway in Node js (aws-lambda-multipart-parser) 使用 Api Gateway、Lambda 函数将图像上传到 S3 存储桶 - Upload Image into S3 bucket using Api Gateway, Lambda funnction 如何使用 AWS 网关和 S3 代理上传大文件 - How to upload large file using AWS Gateway and S3 proxy React 应用程序不会将图像上传到 aws S3 - React app will not upload image to aws S3 AWS HTTP API 网关作为私有 S3 存储桶的代理 - AWS HTTP API Gateway as a proxy to private S3 bucket AWS:无法通过 SDK 将文件上传到私有 S3 - AWS: Can't upload a file to private S3 through SDK Swift - AWS S3 从图片库上传图片并下载 - Swift - AWS S3 Upload Image from Photo Library and download it 在 AWS S3 和 CloudFront 中托管的静态网站 - Static website hosted in AWS S3 and CloudFront AWS S3 上传速度? - AWS S3 Upload speed? Smartsheet API ---- 如何将图像上传到工作表上的单元格,然后将其发送到后端(到 AWS S3,获取 URL,用于 MongoDB) - Smartsheet API ---- how to upload an Image to a cell on a sheet, then send it to back-end (to AWS S3, get URL, for MongoDB)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM