Getting Bytes Loaded
BlitzMax Forums/BlitzMax Beginners Area/Getting Bytes Loaded
| ||
I have a code posted before and im using it to load an image from a site. heres the code.Graphics 400, 300, 0 DrawText "Getting Image...", 140, 144 Flip img:TImage = LoadImage(LoadBank("http::homepage.ntlworld.com/rashida.moussa/loader.bg")) If Not img Then RuntimeError "Unable to download image" Graphics img.width, img.height, 0 'Graphics 1024,768 DrawImage img, 0, 0 Flip WaitKey() End How would i find its filesize and how much is currently loaded? Also how would I download a file from the web and display a progress bar too. |
| ||
Maybe: ? BankSize( Bank:TBank ) |
| ||
How would i find its filesize and how much is currently loaded? Without hacking the Blitzmax modules, I don't think you would be able to se ehow much is currently loaded -- Since blitzmax doesn't do threading yet, and the loading is done by a single command (loadbank), it won't continue your program until the loadbank operation has finished -- meaning it's at 100% then. so no progress bar along the way, unless you change whatever module does the loadbank function and hack a bunch of extra stuff into it to add such functionality. Now, as far as how to get a file size: You have to send an HTTP request to the webserver in question, and view the returned information. You would need to open a port to the server in question on port 80, and send the following strings: (example: this obtains the info for the following image: ![]() HEAD /images/question.gif HTTP/1.1 <enter> Host: www.xlsior.org <enter> Connection: close <enter> <enter> Note that you won't get any response from the server until after you submit the blank line at the end. Only then will it return some information, like this: HTTP/1.1 200 OK Date: Mon, 13 Mar 2006 07:03:13 GMT Server: Apache Last-Modified: Thu, 28 Oct 2004 06:11:20 GMT ETag: "5f95355-6f-41808d88" Accept-Ranges: bytes Content-Length: 111 Connection: close Content-Type: image/gif The Content-Length shows 111: this particular image is 111 bytes in size. If instead of 'HEAD' you use 'GET' in the initial info to send to the server, then after the header info you would receive the actual file itself, in binary. Anyway, after obtaining the info above you know the file size, the last-updated date, the time/date on the server, whether or not the file exists... (HTTP/1.1 220 OK means that the request was succesful. You could also get a HTTP/1.1 404 File Not Found, or HTTP/1.1 301 Permanent Redirect, or something else. You should get 200 (or another 2xx code) if everything went OK. Note that not all servers return the same information. It's possible that a server won't give you a 'size' return, in which case there is no way to know how big the file in question is until after you download it in its entirety. Note: As you can see in the initial codebox above, you do need to specify the domain name in the request. Most webservers nowadays share many websites on a single IP. Without specifying the domain name in the Host: statement, the server won't have any idea whuch domain you are trying to load information for, and you would get the default website on the server -- more than likely, that won't be yours. |
| ||
hmm, thanks. :/ pity it cant be done. i know about that content length one. just cant do a progress bar. :/ what if i downloaded the file instead? of loading it to a bank i mean. can i find the bytes downloaded? |
| ||
You can find the size of the bank, but how much good is that going to do you? Typically the delay will be to actually download the file itself... |
| ||
no i mean what if i want to download a large file. how can i get the size and the bytes recieved. like downloading from the internet. |
| ||
Bump! Another thing added to the list of what BMX cant do. |
| ||
Can't you just load it piece by piece, like with a stream or something? |
| ||
i dont really know how thats why i posted it in the "Beginners" section, thinking that maybe someone would know? |
| ||
You could do it using TCP and reading the file with readbyte. That way you could do a "download progress" as well. |
| ||
thanks. ill try that maybe later. |
| ||
This *might* help. |