简体   繁体   English

如何使用Ruby作为后端将React上的图像上传到Google云端存储

[英]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将文件上载到云存储中您必须准备存储桶。

  1. Create the deposit: gsutil mb gs : // [ YOUR - BUCKET - NAME ] 创建存款:gsutil mb gs:// [你的 - 桶 - 名称]

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.

相关问题 在 Google App Engine 上从 Google Cloud Storage for Ruby on Rails 应用程序加载图像 - Loading images from Google Cloud Storage for Ruby on Rails app on Google App Engine 在Ruby on Rails应用程序中使用云存储存储图像 - Using cloud storage for images in a Ruby on Rails app Rails - 将私有文件上传到 Google Cloud Storage - Rails - Upload private file to Google Cloud Storage 如何使用fog gem将大文件上传(分段上传)到Google Cloud Storage - How to upload(multipart upload) large files to Google Cloud Storage using fog gem 使用carrierwave将图像上传到谷歌云存储,文件名最终被保存,而不是桶中图像的公共链接 - Using carrierwave to upload images to google cloud storage, the file name ends up being saved and not the public link to the image in the bucket 如何使用 Ruby on Rails 4 后端提供 React 应用程序 - How to serve React app with Ruby on Rails 4 backend 如何将本地存储(活动存储)迁移到谷歌云存储 - How to migrate local storage (active storage) to google cloud storage Google Cloud Storage在Ruby中无故返回400错误请求 - Google Cloud Storage returning 400 bad request without reason in Ruby 如何使用S3 API使用回形针gem在Rails应用程序上将红宝石图像上传到IBM Bluemix Object Storage? - How to upload images for ruby on rails app using paperclip gem onto IBM Bluemix Object Storage using S3 API? 如何使用 google-cloud-storage 创建文件? - How to create file with google-cloud-storage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM