gpt4 book ai didi

javascript - 如何强制用户仅将 Firebase 中特定文件的文件上传到某些节点。

转载 作者:行者123 更新时间:2023-11-28 05:53:20 25 4
gpt4 key购买 nike

我正在尝试 Firebase 存储,查看授权用户可以从 Web 客户端上传文件,我想知道是什么阻止用户通过调整 JavaScript 来更改路径。

考虑以下因素

我想按如下方式组织用户文件。

root : {
users :
uid1 : images {}
: audio {}
-users:
uid2 : images {}
: audio {}
-users:
: uid3 : images {}
: audio {}
}

然后上传图片到/userid/images/

        var storage     = firebase.storage();
var storageRef = storage.ref();
var imagesRef = storageRef.child(uid_g).child('images').child(path);

问题:

是什么阻止用户将 child('images') 更改为 child('audio')

我只是想确保我设置的路径不会在存储上更改。

服务器上的规则只允许用户读取和写入他们的数据。

// Grants a user access to a node matching their user ID
service firebase.storage {
match /b/<your-firbase-storage-bucket>/o {
// Files look like: "user/<UID>/path/to/file.txt"
match /user/{userId}/{allPaths=**} {
allow read, write: if request.auth.uid == userId;
}
}
}

最佳答案

您可以继续使用安全规则来创建进一步的路径限制:

service firebase.storage {
match /b/<your-firbase-storage-bucket>/o {
match /user/{userId} {
match /images {
// This will match only /user/{userId}/images
allow read, write: if imageCondition();
}
match /audio {
// If you don't want the user to change to audio, you can either say if false or just don't include this path
allow read, write: if audioCondition();
}
}
}
}

关于javascript - 如何强制用户仅将 Firebase 中特定文件的文件上传到某些节点。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37920085/

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