gpt4 book ai didi

angularjs - 如何检测特定的 firebase 存储路径数据是否已更改

转载 作者:行者123 更新时间:2023-12-05 03:10:53 25 4
gpt4 key购买 nike

firebase 数据库有一个功能,当路径发生变化时我可以再次检索数据

firebase.database().ref('users/' + Auth.uid + '/profileImg').on('value', function(snapshot) { //do things when the data changed});

我想知道是否有人知道 firebase 存储是否做同样的事情?例如,如果我上传另一张个人资料照片,我怎样才能检索到该 imageUrl?

我知道我可以通过下面的方式检索它,但是由于我想检测另一个 Controller 的变化,而这个 Controller 与上传的地方不在同一个 Controller 中,所以这种方法行不通。

                        uploadTask.on('state_changed', function (snapshot) {
// Observe state change events such as progress, pause, and resume
// See below for more detail
}, function (error) {
// Handle unsuccessful uploads
}, function () {
$scope.userProfile = uploadTask.snapshot.downloadURL;
});
}, function (error) {
console.error(error);
});

谢谢!!

最佳答案

Firebase 存储没有内置功能可以在文件更改时主动提醒客户。

通过将 Firebase 存储与 Firebase 实时数据库相结合,您可以轻松构建它。将文件的下载 URL 保存在数据库中并添加一个 lastModified 时间戳:

images
$imageid
downloadUrl: "https://downloadUrl"
lastModified: 123873278327

每当您在 Firebase 存储中上传/更新图像时,更新数据库中的 downloadUrl/时间戳:

uploadTask.on('state_changed', function (snapshot) {
// Observe state change events such as progress, pause, and resume
// See below for more detail
}, function (error) {
// Handle unsuccessful uploads
}, function () {
$scope.userProfile = uploadTask.snapshot.downloadURL;
databaseRef.child('images').child(imageId).set({
downloadUrl: uploadTask.snapshot.downloadURL,
lastModified: firebase.database.ServerValue.TIMESTAMP
})
});

现在您可以通过监听该图像的数据库位置来知道图像何时被修改:

databaseRef.child('images').child(imageId).on('value', function(snapshot) {
// take the downloadUrl from the snapshot and update the UI
});

关于angularjs - 如何检测特定的 firebase 存储路径数据是否已更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38387479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com