我有一个 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/