firebase-storage - 如何知道文件名在firebase云存储中是否包含其他字符串?
问题描述
我想检查上传的图片名称是否包含"thumb_"
。如果文件名包含 "thumb_"
,则用户不允许上传图片。类似的东西:
match/users/{id}/{image}{
if: request.resource.contentType.matches('image/.*') &&
request.resource.size < 1024 *1024 * 2 &&
image.size()<32 &&
!image.includes('thumb_')}
但它给出了错误
Error running simulation — Error: simulator.rules line [13], column [27]. Function not found error: Name: [includes].
我们不能includes()
在安全规则中使用函数。那么我应该使用什么来代替 includes()
?
解决方案
根据Cloud Storage 安全规则的 API 文档,在字符串数据上没有称为“包含”的方法。您可以看到有一个名为“matches”的方法可以让您对字符串执行正则表达式匹配。查看 inimage
中的字符串是否包含字符串“thumb_”:
image.matches('thumb_')
推荐阅读
- angular - 使用 Angular 7 的 IE11 空白页面
- sql - “嵌套”外键关系
- azure-devops - 将 VSTS Web Deploy 包从 Agent 机器部署到另一台机器
- reactjs - 反应,有条件地向组件发送道具
- java - 我的 java 方法没有给出我想要的结果
- javascript - 带有本地存储的便笺
- firebase - 使用 Arduino IDE 将 Arduino Node-MCU 与 Google Firebase 连接
- java - 如何对一维数据(例如一条线)使用 JPEG 压缩算法?
- json - 使用 jq 在 JSON 中附加一个对象,该对象由带有运行时参数的 shell 触发
- javascript - 如何将 JSON API 图像从 API 转换为 base64 以显示在网页上?