xojo.net.httpsocket issues

Was using the classic httpsocket but getting corrupted files in a DL, so though I would try the new version to see if that helped.
In the classic socket, I got a file DL’ed with

Downloader.Get(xURL, downloadFile)

where Downloader is a subclass of httpsocket and downloadFile is a folderItem pointing to the destination. This worked but, as I stated, the resulting file was corrupted.
Making Downloader a subclass of xojo.net.httpsocket, I believe I have to use…

Downloader.Send("Get", myURL, destFile) //from the docs

but when I use this I get a compiler complaint “There are multiple items with this name and it is not clear…”
If I remove the final arg…
Downloader.Send(“Get”, myURL)
The code compiles and runs, but nothing is DL’ed. I have looked at the example projects, but since they are retrieving data and not saving a file, either they are no help or I’m missing something.
Help greatly appreciated.

Make sure the destFile is a Xojo.IO.folderitem and myUrl is of type Text.

Thanks for your reply, Greg.
Adding the line at ** allowed the method to compile.
However, as I am DL’ing several items during the process, I call this method anew for each item.
On the 2nd try, I get an xojo.core.unsupportedoperationexception and the explanation is “A request is already in progress”
I call this method from the Downloader.FileReceived event. Wouldn’t that event only fire after the first file had downloaded?

[code]Private Sub downloadComps(xURL As String, xType As String)
Dim fileName As String = “”
Dim downloadFile As FolderItem
Dim myURL As Text = xURL.ToText

Select Case xType
Case “App”
//I wanted to use the name as it appears in the quizList so that it can contain spaces for easier reading.
fileName = quizList.List(selAppID) + “.qmp2”
downloadFile = SpecialFolder.ApplicationData.Child(“COS”).Child(“Quizzes”).Child(fileName)
Case “Media”
filename = getFileName(xURL)
downloadFile = SpecialFolder.ApplicationData.Child(“COS”).Child(“Pictures_Movies_Sounds”).Child(fileName)
Case “Cat”
filename = getFileName(xURL)
Dim tmpF As FolderItem = SpecialFolder.ApplicationData.Child(“COS”).Child(“QMP_Data”).Child(“QMP_Category Sets”)
//Category Sets may not have been previously created by QMPro
If tmpF <> Nil And Not tmpF.Exists Then
tmpF.CreateAsFolder
End If
downloadFile = tmpF.Child(fileName)
End

** Dim destFile As New Xojo.IO.FolderItem(downloadFile.NativePath.ToText)

If downloadFile <> Nil Then
Downloader.Send(“Get”, myURL, destFile)
noticeFld.Text = "Downloading "+fileName
End If

End Sub[/code]

No. Xojo.Net.HttpSocket only works async. You need to use multiple sockets if you want multiple downloads. Or begin the next download after you get a FileReceived event.

From above…
“I call this method from the Downloader.FileReceived event. Wouldn’t that event only fire after the first file had downloaded”

Or do I miss nderstand what you meant?

[quote=408764:@Roger Clary]From above…
“I call this method from the Downloader.FileReceived event. Wouldn’t that event only fire after the first file had downloaded”

Or do I miss nderstand what you meant?[/quote]
The socket is still in use when the FileReceived event fires. Use Xojo.Core.Timer.CallLater with a time of 1ms to trigger the next download or just use another instance as mentioned above.

Using a timer allows the event stack to unwind enough that the next call will be successful. You can’t start the next download until the previous one has completely finished and the FileReceived event has returned and the socket has been able to clean up from the previous call. In other words, you can queue up the next download from within FileReceived, but you can’t initiate the download from FileReceived. Sorry if I wasn’t clear about that.

Thanks Greg and Tim. With your help it seems to be working correctly using the timer.

Darn! Spoke too soon. It worked once and I thought it was working correctly. Tried a separate DL and kept getting error at:
Downloader.Send(“Get”, myURL, destFile)
“Improperly formed url in the request”
Inspected the URL character by character and couldn’t see a problem. Tried using https with no joy.
Tried going back to the classic HttpSocket but using the Timer to delay between DL items. Still getting a corrupted DL.
Guess I’ll need to withdraw that feature from my app.
Thanks anyway, gentlemen