node.js - 将原始数据上传到 Google Cloud 函数中的 Firebase 存储桶?

标签 node.js firebase google-cloud-storage google-cloud-functions

我有一个 Google Cloud Function,我正在尝试将一些数据保存到 Firebase 存储中。我正在使用 firebase-admin包与 Firebase 交互。

我正在阅读文档( https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-nodejs ),如果文件在本地计算机上,它似乎有关于如何上传文件的明确说明。

// Uploads a local file to the bucket
await storage.bucket(bucketName).upload(filename, {
  // Support for HTTP requests made with `Accept-Encoding: gzip`
  gzip: true,
  metadata: {
    // Enable long-lived HTTP caching headers
    // Use only if the contents of the file will never change
    // (If the contents will change, use cacheControl: 'no-cache')
    cacheControl: 'public, max-age=31536000',
  },
});

就我而言,我有一个 Google Cloud Function,它将在 postbody 中提供一些数据,我想将该数据保存到 Firebase 存储桶中。

我该怎么做呢?上传方法似乎只指定了文件路径,没有数据参数。

最佳答案

使用 save方法:

storage
  .bucket('gs://myapp.appspot.com')
  .file('dest/path/in/bucket')
  .save('This will get stored in my storage bucket.', {
    gzip: true,
    contentType: 'text/plain'
  })

关于node.js - 将原始数据上传到 Google Cloud 函数中的 Firebase 存储桶?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54402379/

相关文章:

Firebase 未将 CORS header 添加到 REST 请求

Android:是否可以将存储在 Google Cloud Storage 中的图像分享到 Instagram?

android - 适用于 IOS/Android 应用程序的谷歌云存储下载

javascript - 仅当数组长度达到 X 个元素时执行

javascript - 使用 this.str 时变量未定义

javascript - 从 requirejs 迁移到 webpack

android - Firebase getValue() 无法正确检索 boolean 值?

node.js - APNS 网关消息错误

javascript - Firebase:TypeError:fbRef.child 不是函数

google-cloud-storage - Google Cloud Storage 上不同目录的不同索引文件可能吗?