将 docx 文件上传到 Firebase 存储后获取带有访问代码的文件 URL

时间:2021-06-23 01:38:52

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

在我的 firebase 可调用云函数上,我目前可以生成一个文档并将其成功上传到 firebase 云存储。我现在的问题是如何将成功上传的文件(带有访问令牌)中的 url 返回到客户端。这是目前我所拥有的,但我不断收到错误消息:

/{.......}/  

const contentBuffer = doc.getZip().generate({ type: "nodebuffer" });

  // reupload to Cloud Storage
  const targetStorageRef = admin.storage().bucket().file("output.docx");
  await targetStorageRef.save(contentBuffer);


// send back a URL and the bucket-name pair to the caller
const location = await targetStorageRef.getDownloadURL();
return { url: location, bucket: targetStorageRef.bucket.name, name: "output.docx" };

我不断收到的错误消息是:Unhandled error TypeError: targetStorageRef.getDownloadURL is not a function

有没有办法把“output.docx”的url返回给客户端?

更新

我更新了我的需求列表以遵循 firebase 文档如下:

const admin = require('firebase-admin');
const {Storage} = require('@google-cloud/storage');
var serviceAccount = require("/Users/johndoe/Downloads/myapp-firebase-adminsdk-1234-567.json");
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  storageBucket: "myapp.appspot.com"
});

我的问题是,当我尝试将该函数部署到 firebase 时,出现错误:

To try redeploying those functions, run:
    firebase deploy --only "functions:test"

To continue deploying other features (such as database), run:
    firebase deploy --except functions

Error: Functions did not deploy properly.

0 个答案:

没有答案