For each URL, I need to get the corresponding file size, without downloading the file it could be a large file. How can I do it in Javascript? HEAD requests always receive just headers and no response body , so no actual data will get downloaded. Here is a sample HEAD request:. The concept above is simple, however if you just go ahead and try to implement it, you may encounter the following problems:. If you run this code with Synchronous XMLHttpRequest, Chrome may try to scare you with the following warning message, displayed in the development console:.
If your Javascript resides in the webpage loaded from mydomain. Here is the error from Chrome:. How to solve that problem? Well, maybe the server that hosts the file you are sizing - maybe that server allows cross domain requests. I would appreciate if someone with more JavaScript knowledge than me would provide better solution to Cross Site problem, better explanation and better code examples.
Find centralized, trusted content and collaborate around the technologies you use most. Connect and share knowledge within a single location that is structured and easy to search.
I'm downloading an entire directory from a web server. It works OK, but I can't figure how to get the file size before download to compare if it was updated on the server or not. Can this be done as if I was downloading the file from a FTP server? Jon: thank for your quick answer. It works, but the filesize on the web server is slightly less than the filesize of the downloaded file.
Using the returned-urllib-object method info , you can get various information on the retrieved document. Example of grabbing the current Google logo:. It's a dict, so to get the size of the file, you do urllibobject. Using these will take advantage of the webserver's caching rules and will return a Not Modified status code if the content hasn't changed.
The size on disk sometimes is different from the actual size of the data. It depends on the underlying file-system and how it operates on data.
When a file is written on the disk, it is stored in a 'sort-of linked list' of disk blocks. When a certain block is used to store part of a file, no other file contents will be stored in the same blok, so even if the chunk is no occupuing the entire block space, the block is rendered unusable by other files. Example: When the filesystem is divided on b blocks, and we need to store b file, two blocks will be occupied.
The first block will be fully utilized, while the second block will have only 88b utilized and the remaining b will be unusable resulting in 'file-size-on-disk' being b. This is why Windows has different notations for 'file size' and 'size on disk'. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Here is the detail of the best of the 3 videos:. One possible solution : I could consult videodownloadhelper and download the heaviest file in terms of MegaByte and it works:. Is there another solution? Skip to content. Star k. New issue. Jump to bottom. Copy link.
How do I know the total size of the video without downloading? Thank you. My Code : youtubedl. Thank you very much for the help. Sign up for free to join this conversation on GitHub.
0コメント