download file

Hi Guys :slight_smile:

i tried to download a file (http://addons.curse.cursecdn.com/files/943/946/Auctionator-4.0.13.zip)

[code]
Dim loadfile as FolderItem
Dim appFolder As FolderItem = SpecialFolder.ApplicationData.Child(gAppName)
Dim prefFolder As FolderItem = appFolder.Child(“download”)
Dim http As New HTTPSocket

'create missing folder
if prefFolder.Exists = false then
prefFolder.createAsFolder
end if

loadfile = prefFolder.Child(listbox1.Cell(1,0) + “.zip”)
msgbox loadfile.NativePath

system.DebugLog(listbox1.Cell(2,4))
http.Get(listbox1.Cell(2,4), loadfile)[/code]

So my probleme is here, the listbox got the link and the name, so in the downloadfolder the app create the zip file but its only 1kb and no download :frowning:

Open the 1kb file in a Text editor. Chances are it contains some debug material from the site.

That URL is a temporary redirect (302) to another location (right now it points to https://addons-origin.cursecdn.com/files/943/946/Auctionator-4.0.13.zip.) You’ll need to detect the 302 status code and then follow the URL in the Location: header of the response.

e.g. in the HeadersReceived event of the HTTPSocket:

Sub HeadersReceived(headers as internetHeaders, httpStatus as integer)
  If httpStatus = 302 Then
    Dim redirecturl As String = headers.CommaSeparatedValues("Location")
    // do something about it
  End If
End Sub

hm ok but then i have to add an httpsocket or? The Dim thing dont have this event… ?

And how can i get the zipfile-name from the url? Tried it with

Dim filename() as String = split(listbox1.Cell(1,4), "/") Dim fields as integer fields = Ubound(filename) msgbox filename(fields-1).ToText

but this dont work… there comes a senseless error “String must have a known encoding” for me?

Public Function GetFilename(f As string) as String
  dim filename as string
  dim parts() as string = f.Split( "/" )
  filename = parts(UBound(parts))
  return filename
End Function

dim s as string = “http://addons.curse.cursecdn.com/files/943/946/Auctionator-4.0.13.zip
dim name as String = GetFilename(s)
MsgBox name

So ok thank you all for the help :slight_smile:

one thing that i dont really understand:

for i as integer = 0 to main.listbox1.listcount -1 dim link as string = listbox1.Cell(i,4) System.DebugLog("link: " + link) dim zipname as String = GetFilename(link) System.DebugLog("zipname: " + zipname) loadfile = prefFolder.Child(zipname) System.DebugLog("zipname: " + loadfile.NativePath) http.Get(link, loadfile) next

i corrected the links and so everything is ok, but it downloads only the last item in the list box not all? whats going wrong here?

are there links that begin with ‘https’ ?

yes and its a secure socket…so it seems i have do Dim the socket in the for part…then it works.

made a test with temporary folder and some links, all ok

  dim prefFolder as FolderItem = SpecialFolder.Temporary.Child("test")
  if not prefFolder.exists  then prefFolder.CreateAsFolder
  
  dim loadfile as FolderItem
  dim link as string
  dim http as HTTPSecureSocket
  
  for i as integer = 0 to main.listbox1.listcount -1
    http = new HTTPSecureSocket
    link = listbox1.Cell(i,4)
    System.DebugLog("link: " + link)
    dim zipname as String = GetFilename(link)
    System.DebugLog("zipname: " + zipname)
    loadfile = prefFolder.Child(zipname)
    System.DebugLog("zipname: " + loadfile.NativePath)
    if http.Get(link, loadfile, 10) then
      System.DebugLog("Download Ok")
    else
      System.DebugLog(str(http.ErrorCode))
    end if
    http.Close
  next

This is what i mean with dim it in the for part :slight_smile:

But how can i Dim a object like this then? If i use the downloader only get the last file again, but i need the DownloadComplete part here :o

dim http as new Downloader

That dont work … there comes an error : Expected a type name but found method

look here
https://www.dropbox.com/s/afrb9neimgm0g37/dl55.xojo_binary_project.zip?dl=1

okay thank you :slight_smile: that helps a lot ^^

the only thing now i have to do is do geht the zipfile name in the downloadcomple handler to extract that package :slight_smile:

make a property loadfile (FolderItem)

and remove the line

dim loadfile as FolderItem

then in DownloadComplete

loadfile.launch

or whatever you want to do with loadfile

i got it already :wink: but its really hard to unzip on windows… i got it to work now! Thank you so much :slight_smile: