如何将 Google 云存储与 react.js 一起使用?
How to use Google Cloud Storage with react.js?
我运行在 Express 上 react.js 应用 运行。我添加了 google-cloud npm module,但我还没有成功。当我需要模块时,我的控制台出现以下错误:
似乎 npm 模块预计 运行 服务器端,但 react.js 运行 客户端。有没有人尝试使用 react.js 应用程序将文件上传到 Google 云存储?
Google API 有一个 JavaScript 客户端库,您可以将其与 Google Cloud Platform 一起使用。 Here's a tutorial 向您展示了如何将其与 Compute Engine API 结合使用。 Google Cloud Storage 的使用原理应该类似。
Your OAuth API scopes need to match the Cloud Storage JSON API, and you'll need to load a storage
client instead of compute
. From there you can use the Cloud Storage JSON API as needed, in the same style as the tutorial uses the Compute Engine API.
您可以使用 firebase 在任何 React 应用程序中轻松访问您的云存储
npm install firebase
然后像任何其他库一样导入和使用它
import firebase from "firebase/app";
import "firebase/storage"
var firebaseConfig = [a key you get from your firebase project]
firebase.initializeApp(firebaseConfig);
var storage = firebase.storage();
随心所欲地使用它。例如
var files = await storage.ref("/images").list();
console.log(files.items);
仅列出名为 images
的云存储文件夹中的文件
您可以在此处获取完整文档 Get started with cloudstorage on web,了解前端 Web 的使用情况,就像您打算在 React 中使用一样
我运行在 Express 上 react.js 应用 运行。我添加了 google-cloud npm module,但我还没有成功。当我需要模块时,我的控制台出现以下错误:
似乎 npm 模块预计 运行 服务器端,但 react.js 运行 客户端。有没有人尝试使用 react.js 应用程序将文件上传到 Google 云存储?
Google API 有一个 JavaScript 客户端库,您可以将其与 Google Cloud Platform 一起使用。 Here's a tutorial 向您展示了如何将其与 Compute Engine API 结合使用。 Google Cloud Storage 的使用原理应该类似。
Your OAuth API scopes need to match the Cloud Storage JSON API, and you'll need to load a storage
client instead of compute
. From there you can use the Cloud Storage JSON API as needed, in the same style as the tutorial uses the Compute Engine API.
您可以使用 firebase 在任何 React 应用程序中轻松访问您的云存储
npm install firebase
然后像任何其他库一样导入和使用它
import firebase from "firebase/app";
import "firebase/storage"
var firebaseConfig = [a key you get from your firebase project]
firebase.initializeApp(firebaseConfig);
var storage = firebase.storage();
随心所欲地使用它。例如
var files = await storage.ref("/images").list();
console.log(files.items);
仅列出名为 images
您可以在此处获取完整文档 Get started with cloudstorage on web,了解前端 Web 的使用情况,就像您打算在 React 中使用一样