[英]How to upload images on React to Google Cloud Storage with Ruby as backend
I'm attempting to upload images from ReactJS to Google Cloud Storage with Ruby as my backend. 我正在尝试将图像从ReactJS上传到Google云端存储,并将Ruby作为我的后端。 I have attempted to send these images through an API I made with Rails, and then upload them directly into Google Cloud Storage through a gem known as 'google-cloud-storage'.
我试图通过我使用Rails创建的API发送这些图像,然后通过名为“google-cloud-storage”的gem将它们直接上传到Google Cloud Storage。 These images are then called back through the API and to be displayed on my frontend which is ReactJS.
这些图像然后通过API回调并显示在我的前端ReactJS上。
There seems to be a lot of issues in doing this, and one of which is a CORS problem when attempting to send an image through the API. 这样做似乎有很多问题,其中一个是尝试通过API发送图像时的CORS问题。
Does anyone have any suggestion or solution on how I can achieve uploading images from ReactJS to Ruby and then to Google Cloud Storage and then being able to call them and display on ReactJS? 有没有人对如何实现从ReactJS上传图像到Ruby再到谷歌云存储,然后能够调用它们并在ReactJS上显示有任何建议或解决方案?
To upload files into Cloud Storage with Ruby before code You have to prepare the bucket. 在代码之前使用Ruby将文件上载到云存储中您必须准备存储桶。
2.Set the default ACL of the deposit as public-read. 2.将存款的默认ACL设置为public-read。 This will allow users to see the images they upload: gsutil defacl set public - read gs : // [ YOUR - BUCKET - NAME ]
这将允许用户查看他们上传的图像:gsutil defacl set public - 读取gs:// [你的 - 桶 - 名称]
3.Install the dependencies. 3.安装依赖项。
4.An implement the code. 4.实现代码。
You can follow the steps before mentioned in How to use Cloud Storage with Ruby[1] link. 您可以按照如何使用Ruby存储与Ruby [1]链接中提到的步骤进行操作。
[1] https://cloud.google.com/ruby/getting-started/using-cloud-storage [1] https://cloud.google.com/ruby/getting-started/using-cloud-storage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.