Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get file size without downloading it

Tags:

flutter

dart

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

like image 440
Makalone LOgman Avatar asked Dec 31 '18 12:12

Makalone LOgman


People also ask

How do I find out file size?

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).

How can I see the size of a file while downloading?

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.

How do I get the size of a file in Python?

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.


1 Answers

Found the answer: HEAD Request.

http.Response r = await http.head(url);
r.headers["content-length"]

Note: r.contentLength; directly doesn't work.

like image 91
Makalone LOgman Avatar answered Oct 31 '22 00:10

Makalone LOgman