如何从 Cloud Functions for Firebase 中读取和写入 Firebase 存储? [英] How can I read and write to Firebase Storage from within Cloud Functions for Firebase?
问题描述
我想将文件从 Cloud Functions for Firebase 保存到 Firebase 存储.
I want to save a file from Cloud Functions for Firebase to Firebase Storage.
我还想稍后将文件从 Firebase 存储读取到 Cloud Functions for Firebase.
I also want to read the file from Firebase Storage to Cloud Functions for Firebase at a later time.
我找不到任何相同的例子.有人可以帮忙吗?
I couldn't find any example for the same. Can someone help?
推荐答案
云函数在相当标准的 V8 Node.js 容器中运行.因此,您可以使用常规 Node SDK for Google Cloud Storage 来与您的文件进行交互.
Cloud Functions run in a fairly standard V8 Node.js container. So you can use the regular Node SDK for Google Cloud Storage to interact with your files.
链接中的一段代码:
// Upload a local file to a new file to be created in your bucket.
bucket.upload('/photos/zoo/zebra.jpg', function(err, file) {
if (!err) {
// "zebra.jpg" is now in your bucket.
}
});
但实际上:只需转到链接,它包含的示例比我愿意在此处复制/粘贴更好.
But really: just go to the link, it contains a better example than I'm willing to copy/paste here.
这篇关于如何从 Cloud Functions for Firebase 中读取和写入 Firebase 存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!