how do I check the file size of a video in flutter before uploading

谁说胖子不能爱 提交于 2020-05-25 06:48:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!