繁体   English   中英

我想限制上传到firebase存储的pdf文件大小。 我希望该用户可以上传最大7MB的文件

[英]I want to limit the pdf file size uploaded to firebase storage. I want that user can upload a file with maximum size of 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中获取文件大小?

Retrofit允许您仅在一次上传特定尺寸。 本网站有从基础到复杂系列文章的详细教程。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM