Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the fastest way to get size of an online file [ http ] [duplicate]

I'm working on a YouTube Downloader, which gets sizes of all qualities available but usually that takes a very long time and sometimes it just goes like a lightning !

I wrote this Function and it's pretty good [ only sometimes as I said before ] !

    Uri url = new Uri("http://example.com/document.docx");
    System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
    System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
    response.Close();

    // iSize will handle the size of the file in bytes
    Int64 iSize = response.ContentLength;

.

So, Is there a faster way to do this ? ( Put on your mind that the files which will be measured are more than eight files ) .

.

In advance, thank you so much ;

like image 903
Alaa Alrifaie Avatar asked Dec 15 '25 15:12

Alaa Alrifaie


1 Answers

That completely depends on how well-behaved the HTTP server is.

The specification says that you can send a HEAD request to get response headers like Content-Length without serving the file.

However, many servers don't do that.

like image 117
SLaks Avatar answered Dec 17 '25 06:12

SLaks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!