簡體   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