简体   繁体   中英

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

I want put a limitation on firebase storage. That is user can upload a pdf file of maximum size of 7MB. And How can i reduce the size of pdf file? is there any way in android.

I don't know the solution of my question. I find a lot but doesn't get my answer. Can someone help me with firebase security rules? I am not familiar with that doesn't find any answer about this.

The Firebase documentation on security rules has an example that shows (amongst others) how to set the maximum size of files that can be stored:

 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 } } } } 

Since these rules will only be applied after the actual upload has completed (but before the file is actually stored in your storage bucket), you'll typically also want to check the file size in your Android app before uploading it, to prevent using bandwidth for a file that is too large. For some examples of how to check the local file size on Android, see Get the file size in android sdk?

Retrofit allows you to upload certain size only at a single time. This site has detailed tutorial from basic to complicated series of articles.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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