Größe einer hochgeladenen Datei herausfinden
-
Hallo....
öhm.. wie kann ich herausfinden, wie groß eine Datei hinter einer URL ist?
-
Einfach den Wert unter einer Variable speihern.
Evt. musst du mit dem buffer arbeiten.
-
Meinst du, zuerst mit InternetReadFile solange Teile der Datei einlesen, bis man sie ganz hat, und dann einfach nur gucken, wie viel man eingelesen hat? _''
Anders/Besser geht es nicht?
-
Kannst mal mit HttpQueryInfo und HTTP_QUERY_CONTENT_LENGTH probieren.
-
Hört sich gut an, ich schau mal, was sich dahinter verbirgt
Danke

-
PS:
Aber die Datei herunter zu laden funktioniert besser mit InternetReadFile?
-
Irgendwíe bek0mme ich das nicht hin...
Bei mir kommt etwas gaaanz anderes heraus, als die Größe der Datei
-
Haste auch richtig deklariert ?
Poste doch mal deinen Code.
Man übersieht schonmal öfters etwas.
Schamuer.
-
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnarwebtool/html/msdn_inet.asp
MSDN schrieb:
Let's say that we want to get the size of the HTML page before downloading it so that we can allocate a buffer in the exact size. HttpQueryInfo will get the size of the Web page.
A word of caution: Not all Web pages support getting the page size. (For example, www.toystory.com and www.movielink.com don't support this functionality.) Also, TCP/IP can send less data than requested. Therefore, your application should handle both of these cases and loop around InternetReadFile until the result is True and *lpdwNumberOfBytesRead is 0.
The code to open the file http://www.microsoft.com/msdn/msdninfo/ using HttpOpenRequest, HttpSendRequest, and HttpQueryInfo is shown below. The error checking has been removed.
// Open Internet session. HINTERNET hSession = ::InternetOpen("MSDN SurfBear", PRE_CONFIG_INTERNET_ACCESS, NULL, INTERNET_INVALID_PORT_NUMBER, 0) ; // Connect to www.microsoft.com. HINTERNET hConnect = ::InternetConnect(hSession, "www.microsoft.com", INTERNET_INVALID_PORT_NUMBER, "", "", INTERNET_SERVICE_HTTP, 0, 0) ; // Request the file /MSDN/MSDNINFO/ from the server. HINTERNET hHttpFile = ::HttpOpenRequest(hConnect, "GET", "/MSDN/MSDNINFO/", HTTP_VERSION, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0) ; // Send the request. BOOL bSendRequest = ::HttpSendRequest(hHttpFile, NULL, 0, 0, 0); // Get the length of the file. char bufQuery[32] ; DWORD dwLengthBufQuery = sizeof(bufQuery); BOOL bQuery = ::HttpQueryInfo(hHttpFile, HTTP_QUERY_CONTENT_LENGTH, bufQuery, &dwLengthBufQuery) ; // Convert length from ASCII string to a DWORD. DWORD dwFileSize = (DWORD)atol(bufQuery) ; // Allocate a buffer for the file. char* buffer = new char[dwFileSize+1] ; // Read the file into the buffer. DWORD dwBytesRead ; BOOL bRead = ::InternetReadFile(hHttpFile, buffer, dwFileSize+1, &dwBytesRead); // Put a zero on the end of the buffer. buffer[dwBytesRead] = 0 ; // Close all of the Internet handles. ::InternetCloseHandle(hHttpFile); ::InternetCloseHandle(hConnect) ; ::InternetCloseHandle(hSession) ; // Display the file in an edit control. pEditCtrl->SetWindowText(buffer) ;