问题
I want to upload a video file to my cloud storage but I want to check the size of the video file before I upload. how to achieve this
回答1:
If you have the path of the file, you can use dart:io
var file = File('the_path_to_the_video.mp4');
You an either use:
print(file.lengthSync());
or
print (await file.length());
Note: The size returned is in bytes
.
回答2:
If you have file object then you can call length() on the file object.
int fileLength = await file.length();
length() returns a Future<int>
that
completes with the length in bytes.
来源:https://stackoverflow.com/questions/53036328/how-do-i-check-the-file-size-of-a-video-in-flutter-before-uploading