我正在努力实现以下目标。但是,我不知道,因为我是 firebase 的初学者。
到此为止,我已经完成了。现在,我需要调整上传图像的大小。
为此,我正在尝试使用 Cloud Functions,每当向 Firestore 数据库添加新条目时,我都会调用 Cloud fountion,它可以访问图像的下载 URL,使用此下载 URL,我需要调整图像大小。请帮忙。
请让我知道,如果有更好的方法来实现这一点。(我知道应该有:P)
编辑 1
谢谢弗兰克的回复。
我有下面的云函数,每插入一个帖子都会调用它。我从 eventSnapshot 获取图像的下载 URL。我需要调整该位置的图像大小。请帮忙。
exports.resizeImage = functions.firestore
.document('posts/{postId}')
.onCreate(event => {
var eventSnapshot = event.data.data();
//In this eventSnapshot I am getting the document, and I can get the download URL from the document
});
Run Code Online (Sandbox Code Playgroud)
我已经分析了创建缩略图的示例,但是为此,我需要
存储对象,并且只有在更改存储对象时才会调用它。但是,当 onWrite 在 firestore 中调用时,我需要创建缩略图。
exports.generateThumbnail = functions.storage.object().onChange((event) => {
// File and directory paths. …Run Code Online (Sandbox Code Playgroud) javascript firebase google-cloud-functions firebase-storage google-cloud-firestore
使用下面的查询,我可以获取文档和 doc.data().name 以获取键“name”的值。我想获取该文档中的所有密钥。我怎么能得到那个?
var docRef = db.collection("cities").doc("SF");
docRef.get().then(function(doc) {
if (doc.exists) {
console.log("Document data:", doc.data());
//**I want to get all keys in the document here.**
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
}).catch(function(error) {
console.log("Error getting document:", error);
});
Run Code Online (Sandbox Code Playgroud)