What API do I use to find the size of a file using HTTP protocol? The file is opened as follows, I have tried InternetQueryDataAvailable but that only yeilds the portion of the file available for immediate reading not the complete file size, it generally coughs at around 14K. Do I have to create an ever expanding buffer and pray that I don't run out of memory before the file is downloaded ? I want to be able to read the file into memory and bypass saving the file if possible. If it is not possible to do that I can create a temp download file and move it in chunks to the file then read it into memory, that is already done but I am just looking for a way to avoid it if the file is small enough.

invoke InternetOpen,"MyApp",INTERNET_OPEN_TYPE_PRECONFIG,\

NULL,NULL,NULL
mov [hInternet],eax

invoke InternetOpenUrl,[hInternet],[pURLName],0,0,\
INTERNET_FLAG_EXISTING_CONNECT + INTERNET_FLAG_KEEP_CONNECTION, 0
mov [hURL],eax
or eax,eax
; some error checking here

;invoke InternetQueryDataAvailable,[hURL],OFFSET cbFile,NULL,NULL


PS FTP is not an option, the whole point is to avoid that.
Posted on 2004-02-14 16:03:52 by donkey
The HTTP protocol has an optional Content-length entry in the header.
So only if that entry is present, you can know the entire filesize, it's not required (would be rather hard for certain dynamic pages for example).
So yes, you cannot depend on knowing the filesize beforehand, and you should realloc your buffer until all data is received, or something.
Posted on 2004-02-14 17:04:55 by Henk-Jan
Oh well, that is about what I thought. I will create a temp file and read until I get a cbRead of zero then read it back into a buffer. At least that way I can verify that it doesn't exceed maximum size.
Posted on 2004-02-14 17:08:14 by donkey
HttpQueryInfoA
Posted on 2004-02-14 17:18:04 by evlncrn8
You know I have that API bookmarked but I could not find the flag to read the size of the URL in bytes, now I look at it again and see HTTP_QUERY_CONTENT_LENGTH, too much to process at one time I geuss.
Posted on 2004-02-14 17:34:55 by donkey
yup, been there, done that, i had to look it up 5 times before i got it working, turns out the ptr u have to pass for the buffer size has to be a ptr to a dword containing the buffer size too, annoying way to do it, caused me numberous crashes hehe, then again it was quite late at night and i really should have been in bed instead of coding ;)
Posted on 2004-02-14 18:19:27 by evlncrn8
Yeah,

I guess the most important part is to also specify HTTP_QUERY_FLAG_NUMBER or you get a string and when you check it, well the number is a bit high and VirtualAlloc fails.
Posted on 2004-02-14 19:27:00 by donkey