使用SDK跳过cloudfront将图像上传到S3
设置:
我们正在运行一个电子商务网站,由 Cloudfront-->ALB-->EC2 组成。我们通过 Cloudfront 行为提供来自 S3 的图像。
问题:
我们的管理 URL 类似于 example.com/admin。我们通过管理面板将产品图像作为 zip 文件上传,并通过 cloudfront 进行传输。每个大小约为 100MB-150MB 的 zip 文件由大约 100 张图像组成。在上传 zip 文件时,我们遇到了来自 cloudfront 的 502 网关错误,因为它花费了超过 30 秒,这是 cloudfront 的默认超时值。
预期的解决方案:
有没有一种方法可以跳过云端,只上传图片?
有没有其他方法可以增加cloudfront的超时值?
注意:任何推荐的解决方案都将受到高度赞赏
Setup:
We are running a E-commerce website consists of Cloudfront-->ALB-->EC2. we are serving the images from S3 via cloudfront behaviour.
Issue:
Our admin URL is like example.com/admin. We are uploading product images via admin panel as a zip file that goes via cloudfront.Each zip file size around 100MB-150MB consists of around 100 images. While uploading the zip file we are facing 502 gateway error from cloudfront since it took more than 30sec, which is default time out value for cloudfront.
Expected solution:
Is there a way we can skip the cloudfront for only uploading images?
Is there any alternate way increasing timeout value for cloudfront??
Note: Any recommended solutions are highly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CloudFront 是一项 CDN 服务,可通过在边缘位置缓存静态文件来帮助您加快服务速度。所以它不会帮助你上传方面。
我认为,对于上传图像功能,你应该使用AWS SDK直接与S3连接。
CloudFront is a CDN service to help you speed up your services by caching your static files in edge location. So it won't help you in uploading side
In my opinion, for the uploading images feature, you should use the AWS SDK to connect directly with S3.
如果您想从客户端直接将文件上传到 s3,我强烈建议您使用 s3 预签名 URL。
您在 API 中创建一个端点来为特定对象 (myUpload.zip) 创建预签名 URL,将其传回客户端并使用该 URL 进行上传。它很安全,您无需公开任何上传凭据。确保将过期时间设置为合理的时间(一小时)。
有关预签名 URL 的更多信息,请参见此处 https:// aws.amazon.com/blogs/developer/generate-presigned-url-modular-aws-sdk-javascript/
If you want to upload files directly to s3 from the client, I can highly suggest using s3 presigned URLs.
You create an endpoint in your API to create the presigned URL for a certain object (myUpload.zip), pass it back to the client and use that URL to do the upload. It's safe, and you won't have to expose any credentials for uploading. Make sure to set the expiration time to a reasonable time (one hour).
More on presigned URLs's here https://aws.amazon.com/blogs/developer/generate-presigned-url-modular-aws-sdk-javascript/