通过反转Nginx上载到S3 [英] Upload into S3 by reversing Nginx

查看:79
本文介绍了通过反转Nginx上载到S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储桶,可以通过NodeJS轻松地将文件上传到其中.但不幸的是,我无法直接使用ReactJS上传文件.我尝试时会返回CORS错误.

I have a Bucket that I can easily upload my files into that by NodeJS. But unfortunately, I can't directly upload my files with ReactJS. It returns CORS error when I try.

在以下位置访问XMLHttpRequest'https://test_bucket.s3.ir-thr-at1.arvanstorage.com/temp.png?uploads'来自来源"https://example.com"的信息已被CORS政策阻止:对预检请求的响应未通过访问控制检查:没有HTTP正常状态.

Access to XMLHttpRequest at 'https://test_bucket.s3.ir-thr-at1.arvanstorage.com/temp.png?uploads' from origin 'https://example.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

我在此处问了一个问题,但我没有任何结果.

I asked a question here but I didn't get any result.

现在,我正在使用Nginx与后端进行代理.Nginx是否可以直接将我的ReactJS代理到S3 Bucket?

Now, I'm using Nginx for proxying with my backend. Is that possible to proxy directly from my ReactJS to S3 Bucket by Nginx?

推荐答案

简短答案.并不真地.您正在混淆事物.首先

Short answer. Not really. You are mixing up things. First of all

请勿在整个世界上存储/共享您的AWS API密钥和秘密

在ReactJS应用程序中具有API密钥和密钥将使其对他人可读!!你不要这个!相信我!

Having the API Key and Secret in your ReactJS App will make it readable to others!! You do not want this! Trust me!

在您的情况下,我建议您为ReactJS应用程序使用客户端组件,并与一个小型轻量级后端服务进行对话,以保护您的机密.

In your case I would recomand using a client side component for your ReactJS App talking to a small lightweight backend service holding your secrets.

使用Express的ReactJS和NodeJS的一个非常有用的实现是: https://www.npmjs.com/package/react-s3-uploader

A quite usefull implementation for ReactJS and NodeJS using Express is this: https://www.npmjs.com/package/react-s3-uploader

后端服务可以由NGINX代理.当然.确保从您的前端代码可以访问"sign-url".

The Backend-Service can be proxied by NGINX. Of course. Make sure the ´sign-url´ is reachable from your frontend code.

https://www.npmjs.com/package/react-s3-uploader#server-side

这将为您工作.很确定.

This will work for you. Pretty sure.

这篇关于通过反转Nginx上载到S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆