Firebase存储URL,新文件保留相同的访问令牌 [英] Firebase storage url, new file keep same access token

查看:69
本文介绍了Firebase存储URL,新文件保留相同的访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重复项: Firebase存储URL不断更改并带有新令牌

当用户上传个人资料照片时,我将其存储在firebase存储中,文件名为uid. 假设用户随后发表了100条帖子+ 500条评论,然后更新了他们的个人资料图片.

When a user uploads a profile pic I store this in firebase storage with the file name as the uid. Lets say the user then goes and makes say 100 posts + 500 comments and then updates their profile image.

当前,我有一个触发器,可以用来更新所有发布和评论文档中的个人资料图片网址.我必须这样做的原因是,当更改存储中的映像时,访问令牌也会更改,并且这是url的一部分,因此旧的url不再起作用.

Currently I have a trigger which goes and updates the profile image url in all of the post and comment documents. The reason I have to do this is that when the image is changed in storage the access token is changed and this is part of the url so the old url no longer works.

我想做的是不更改访问令牌.如果可以,我可以避免进行大量更新,而这些更新会大大增加我的Firestore写入量.

What I want to do is not have the access token change. If I can do this I can avoid the mass updates that will massively increase my firestore writes.

有没有办法做到这一点?还是其他选择?

Is there any way to do this? or an alternative?

推荐答案

@Prodigy在此处提供的答案: https://stackoverflow. com/a/64129850/10222449 我试过了,效果很好. 这将节省数百万的写入.

Answer provided by @Prodigy here: https://stackoverflow.com/a/64129850/10222449 I tried this and it works well. This will save millions of writes.

var storage = firebase.storage();
    var pathReference = storage.ref('users/' + userId + '/avatar.jpg');
    pathReference.getDownloadURL().then(function (url) {
        $("#large-avatar").attr('src', url);
    }).catch(function (error) {
        // Handle any errors
    });

这篇关于Firebase存储URL,新文件保留相同的访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆