java - 我想限制上传到 Firebase 存储的 pdf 文件大小。我希望该用户可以上传最大大小为 7MB 的文件
问题描述
我想限制 Firebase 存储。也就是说,用户可以上传最大大小为 7MB 的 pdf 文件。以及如何减小 pdf 文件的大小?有什么办法在android中。
我不知道我的问题的解决方案。我找到了很多,但没有得到我的答案。有人可以帮我制定 Firebase 安全规则吗?我对此不熟悉,找不到任何答案。
解决方案
Firebase 有关安全规则的文档有一个示例,该示例显示(除其他外)如何设置可以存储的文件的最大大小:
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 } } } }
由于这些规则只会在实际上传完成后应用(但在文件实际存储在存储桶中之前),因此您通常还需要在上传之前检查 Android 应用中的文件大小,以防止占用带宽对于太大的文件。有关如何在 Android 上检查本地文件大小的一些示例,请参阅在 android sdk 中获取文件大小?
推荐阅读
- java - 将 Android Gradle 插件从当前版本 3.4.1 更新到版本 3.5.2 和 Gradle 到版本 5.4.1 失败
- python - 从 Matlab 翻译:新问题(复杂的 ginzburg 朗道方程
- node.js - 从 EC2 实例查询 DynamoDB 时遇到高延迟
- postgresql - 使用 EF Core 3.0 的 postgis 调用 postgresql 10.10 数据库的 npgsql 存储函数时出现问题
- android - 无法发送简单的 GET Http 请求
- ios - 如何在 ios/swift 中将 url 转换为字符串?
- assembly - 为什么编译器在从函数返回的 MIPS "j" 指令之后放置一条指令?
- asp.net-core - asp.net 核心 cookie 问题
- jupyter-notebook - 无法将 Jupyter Notebook 添加到 IBM Cloud 的 Watson Studio 中的项目
- c++ - 如何将字符附加到字符数组?