Dis*_*ive 4 node.js google-cloud-storage firebase 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',
},
});
Run Code Online (Sandbox Code Playgroud)
就我而言,我有一个 Google Cloud 函数,它将在 postbody 中提供一些数据,我想将该数据保存到 Firebase 存储桶中。
我该怎么做呢?upload方法似乎只指定了文件路径,没有数据参数。
使用保存方法:
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'
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3058 次 |
| 最近记录: |