简体   繁体   中英

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. 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'. These images are then called back through the API and to be displayed on my frontend which is 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.

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?

To upload files into Cloud Storage with Ruby before code You have to prepare the bucket.

  1. Create the deposit: gsutil mb gs : // [ YOUR - BUCKET - NAME ]

2.Set the default ACL of the deposit as public-read. This will allow users to see the images they upload: gsutil defacl set public - read gs : // [ YOUR - BUCKET - NAME ]

3.Install the dependencies.

4.An implement the code.

You can follow the steps before mentioned in How to use Cloud Storage with Ruby[1] link.

[1] https://cloud.google.com/ruby/getting-started/using-cloud-storage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM