All I want to do is download a file from the internet, check its hash and save it to a specified location.
I’m a little confused on how to do it. The included Xojo Examples and other example code I’ve seen do way more than what I want so I’m not sure what code I need and what I don’t.
I am creating a TCG game and upon first launch I need the game to download the latest Card Definition file stored in my cloud server. Also this file will be updated as I add more cards to the game.
I figured the best approach is to create a Global “DownloadFile” Function where I pass the web address and save location. This way I can download needed files from anywhere in the game without having duplicate code everywhere.
Check the language reference. There’s a form of Get that takes a folderitem and downloads to it. But really, all files are strings. You can read any file that way.
While the file is being downloaded, I get the Beach Ball, how do I incorporate a progress bar as I need the file to completely download before executing more code.
If you don’t want your app to stall while downloading, use the async version (no timeout). Put the rest of your code in the completed event. You can use AddHandler to make it more flexible.
This is all new to me so I need some example code to learn what to do. I am very visual.
I can’t store the contents of the file in a variable as the file will grow to several hundred MBs so it needs to be saved to storage while downloading.
Also I’ve been out of the loops for several years so some of this stuff is all new to me again so please bear with me
There is no other way to compare how many bytes have downloaded to the file size? I thought there were other methods that you can call to find out how big a file is before downloading it?
I’ve already looked at the HTTPSocket.ReceiveBytes before posting but it doesn’t tell me how to use it. All it says is that it fires periodically but it doesn’t give me a way to see the data.
EDIT: I’m still getting used to the Xojo IDE. I’m used to the old RealBasic IDE that let me click the arrow on an item and see all the available methods. I keep forgetting that I have to manually add an event to a control.
Calling Get without a timeout parameter will cause the download to happen asynchronously with the events firing as things are downloaded. You do not need a Thread or a Timer, just a little code in the ReceiveProgress event handler.
Here’s a simple example (to be included in the next release of Xojo) that shows you how you can use an HTTPSocket to download a file and display a ProgressBar.
[quote=88303:@Charles Fasano]That didn’t quite work. I got a NilObjectException on the:
ProgressBar.Maximum = totalBytes
part.[/quote]
Progressbar.Maximum should be
TheNameOfMyProgressBarInstance.Maximum
(replace “TheNameOfMyProgressBarInstance” with the name of your progressbar instance)
same for Progressbar.Value