使用 firebase 函数 v2 将文件上传到 firebase 存储 [重复]

Upload file to firebase storage with firebase function v2 [duplicate]

提问人:Matias 提问时间:11/6/2023 最后编辑:Doug StevensonMatias 更新时间:11/6/2023 访问量:35

问:

我有点挣扎。我正在尝试使用 firebase 函数上传文件。 这是我的代码

export const uploadFile = onRequest(async (req, res) => {
  const fileName = req.query.fileName+"";
  console.log("fileName: ", fileName);
  const fileRef = await admin.storage().bucket("gs://some-bucket.appspot.com")
   .upload(fileName, {destination: "testFile.jpg"});
  res.status(200).send(fileRef);
});

这是函数的日志: 错误:ENOENT:没有这样的文件或目录,打开“https://www.shutterstock.com/image-illustration/football-stadium-night-imaginary-modelled-260nw-1912601503.jpg”

我正在尝试使用 firebase 函数将文件上传到查询/正文中

JavaScript 节点.js google-cloud-functions firebase-storage

评论

0赞 Doug Stevenson 11/6/2023
您无法使用提供的 SDK 直接从 URL(显示为 中的 URL)上传到存储。您必须先将 URL 本地下载到缓冲区或文件,然后将其内容上传到存储。fileName
0赞 Matias 11/6/2023
谢谢道格!!我不知道。您有机会给我一个在本地下载 URL 的示例吗?我正在尝试这样做,但目前没有成功:(
0赞 Frank van Puffelen 11/6/2023
在 Node 中下载文件的例子已经有很多.js:google.com/search?q=node.js+download+file+from+url。如果您在使其适用于您的特定案例时遇到困难,我建议您打开一个新问题,并具有自己的最小重现

答: 暂无答案