Downloading images

Desktop application

The code below do not works as expected:

Var socket2 As New HTTPSecureSocket
Var Img1_FI As FolderItem
Var Img2_FI As FolderItem
Var Img3_FI As FolderItem

socket2.ConnectionType = SSLSocket.TLSv12

Img1_FI = SpecialFolder.Desktop.Child("Fim-w900.gif")
socket2.Get(Image_URL,Img1_FI)

Img2_FI = SpecialFolder.Desktop.Child("Fam-w1500.gif")
socket2.Get(Image_URL + "?width=1500",Img2_FI)

Img3_FI = SpecialFolder.Desktop.Child("Foom-h1500.gif")
socket2.Get(Image_URL + "?height=1500",Img3_FI)

At first I used only one FolderItem, but I had to change.

I get my three files, but the data is written on one (all three images), the two other files sizes are 0Bytes.

When I comment the other two, each image is on desktop.

socket1 is used to download a web page as text.

Ideas ?

seems this Get can be Asynchronously or Synchronously
https://documentation.xojo.com/api/deprecated/httpsecuresocket.html#httpsecuresocket-get

without events i think you will use Synchronously with parameter timeout in seconds.

Yes he needs to check the boolean return value or use Call before the method (to use sync).

Var socket2 As New HTTPSecureSocket
Var Img1_FI As FolderItem
Var Img2_FI As FolderItem
Var Img3_FI As FolderItem

socket2.ConnectionType = SSLSocket.TLSv12

Img1_FI = SpecialFolder.Desktop.Child("Fim-w900.gif")
Call socket2.Get(Image_URL,Img1_FI, 60)

Img2_FI = SpecialFolder.Desktop.Child("Fam-w1500.gif")
Call socket2.Get(Image_URL + "?width=1500",Img2_FI, 60)

Img3_FI = SpecialFolder.Desktop.Child("Foom-h1500.gif")
Call socket2.Get(Image_URL + "?height=1500",Img3_FI, 60)

Added the timeout parameter and call (to ignore the boolean return value )

Thank you.

But I think (I will check) that I already tested the use of Yield (removed from the shared code).

I already was able to get 31 files (the whole october run) with only one size. I try with all three:

with

socket2.Yield = True

I get a ton of 0Byte files. I try without:

Same result.

The application apparently wrote the three files contents into the last FolderItem (all three into the same file, overwriting them) and let the two others empty/with 0Bytes.

without events i think you will use Synchronously with parameter timeout in seconds.
That is what I do in the “main code”. But for some reason, this takes forever.

The current code is a test to speed up the process. 5 to 10 minutes to get 3 images… is a real shame. The previous code used InternetHeader contents to get the original file name, etc. while this code compute a file name from the start date (using the loop index, limiting the download to a month or I will get a file named October 36, 2021…)

Do you have another advice ?

Hi Derk (and thanks),

I do not saw the Time Out parameter in the LR !

I try your advice right now…

It works fine !

(OK, RAW Coding, but the concept proves to be OK. More work to be done).

9 minutes to download all 93 files (3 x 31) for a total of 188.5MB). It’s fine, I’m happy.

1 Like