设置Firebase存储空间文件大小和文件编号限制
我正在使用AngularFire2将图像成功上载到Firebase存储 我有下面的上传代码设置Firebase存储空间文件大小和文件编号限制,firebase,ionic2,firebase-storage,angularfire2,Firebase,Ionic2,Firebase Storage,Angularfire2,我正在使用AngularFire2将图像成功上载到Firebase存储 我有下面的上传代码 this.AfStorage.ref(`images/${userId}/${timeStamp}`).putString(base64Image,'data_url'); 有几个问题我想解决 如何设置文件大小的限制?这意味着我希望用户能够上传小于10mb的文件 如何限制文件号?这意味着我希望一个用户只能上传3个文件 如果没有firebase服务器大小的解决方案,请建议一些客户端大小的解决方案 感谢要限
this.AfStorage.ref(`images/${userId}/${timeStamp}`).putString(base64Image,'data_url');
有几个问题我想解决
感谢要限制上载的大小,请参见以下内容:
service firebase.storage{
匹配/b/{bucket}/o{
匹配/图像{
//级联读取到任何路径上的任何图像类型
匹配/{allImages=**}{
允许读取;
}
//允许将文件写入路径“images/*”,但需遵守以下限制:
//1)文件小于5MB
//2)内容类型为图像
//3)上传的内容类型与现有内容类型匹配
//4)文件名(存储在imageId通配符变量中)少于32个字符
匹配/{imageId}{
允许写入:如果request.resource.size<5*1024*1024
&&request.resource.contentType.matches('image/*'))
&&request.resource.contentType==resource.contentType
&&imageId.size()<32
}
}
}
}
使用安全规则无法限制文件的数量,因此您必须查看以下解决方法:
- (似乎暗示这是可能的,但我从未尝试过)
service firebase.storage {
match /b/{bucket}/o {
match /images {
// Cascade read to any image type at any path
match /{allImages=**} {
allow read;
}
// Allow write files to the path "images/*", subject to the constraints:
// 1) File is less than 5MB
// 2) Content type is an image
// 3) Uploaded content type matches existing content type
// 4) File name (stored in imageId wildcard variable) is less than 32 characters
match /{imageId} {
allow write: if request.resource.size < 5 * 1024 * 1024
&& request.resource.contentType.matches('image/.*')
&& request.resource.contentType == resource.contentType
&& imageId.size() < 32
}
}
}
}