How to get file size from URL (in Flutter)? I am able to get it by using:
http.Response response = await http.get(url);
print(response.contentLength);
But that downloads the entire file. Is it possible to get the file size without entirely downloading it? Thanks
Right-click the file and click Properties. The image below shows that you can determine the size of the file or files you have highlighted from in the file properties window. In this example, the chrome. jpg file is 18.5 KB (19,032 bytes), and that the size on disk is 20.0 KB (20,480 bytes).
You can install chrono and when you click on the downloading file or downloaded file there you can see the size in bytes. Just as an aside: note that this actually starts the download.
The python os module has stat() function where we can pass the file name as argument. This function returns a tuple structure that contains the file information. We can then get its st_size property to get the file size in bytes.
Found the answer: HEAD Request.
http.Response r = await http.head(url);
r.headers["content-length"]
Note: r.contentLength;
directly doesn't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With