Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set maximum file size using FilePicker in Flutter

I need to avoid files bigger than 10MB.

I can check the file size doing something like this:

final file = File('whateveripicked.mp4');
print(file.lengthSync()); 

And do some checks after but that doesn't provide the best UX.

I'd like to exclude big files and hide them on the gallery. Is this kind of filter possible?

like image 458
Dani Avatar asked Jun 09 '26 01:06

Dani


1 Answers

final f = File('whateveripicked.mp4');            
int sizeInBytes = f.lengthSync();
double sizeInMb = sizeInBytes / (1024 * 1024);
if (sizeInMb > 10){
    // This file is Longer the
}
like image 157
Nilesh Senta Avatar answered Jun 11 '26 21:06

Nilesh Senta