Page 1 of 1

Download file to desktop...

Posted: Mon Apr 23, 2018 3:44 pm
by cmhjon
Hi all,

I want my (cross platform) app to be able to download a file from my website. I want the file to download to the DESKTOP regardless of whether the user is on a Mac or Windows PC. The file to download is on my web server and I've tested the URL and the file downloads fine. I just can't seem to get it to download via script:

on mouseUp
put specialFolderPath("Desktop") & "http://www.mywebserver.com/FileToDownload.zip" into tDownloadLink
load URL tDownloadLink
end mouseUp

Can someone correct the code so this will work?

Thanks,
Jon :)

Re: Download file to desktop...

Posted: Mon Apr 23, 2018 3:53 pm
by dunbarx
Hi.

At least on a Mac, the single word "deskTop" is an incomplete pathname.

I would have to use: "/users/craignewman/desktop/"

HTH

Craig Newman

Re: Download file to desktop...

Posted: Mon Apr 23, 2018 3:58 pm
by Klaus
Hi Jon,

"load url..." will only load that URL into a cache and you have to take care what to do with the file after successful download.

But -> specialFolderPath("desktop") & "http:// www. mywebserver.com /FileToDownload. zip"
will NOT give you a valid url to download a file from! On my machine it will read:
/Users/klaus2/Desktophttp://www. mywebserver.com /FileToDownload. zip 8)

You want something like;

Code: Select all

on mouseUp

  ## File to save to on HD:
  put specialFolderPath("Desktop") & "/FileToDownload.zip" into tDownloadedFile

  ## File on server:
  put "http://www.mywebserver.com/FileToDownload.zip" into tUrl
  libUrlDownloadtoFile tUrl, tDownloadedFile
end mouseUp
Best

Klaus

Re: Download file to desktop...

Posted: Mon Apr 23, 2018 4:55 pm
by bogs
Well, if I understood the question correctly (always possibly did not :wink: )
I want my (cross platform) app to be able to download a file from my website. I want the file to download to the DESKTOP regardless of whether the user is on a Mac or Windows PC.
I would think this should work (I don't have a webserver/filename to test at the moment)

Code: Select all

on mouseUp
   put URL ("file:http://www.mywebserver.com/FileToDownload.zip") \
         into URL("file:" & specialFolderPath("desktop") & slash & "FileDown.zip")   
end mouseUp

Re: Download file to desktop...

Posted: Mon Apr 23, 2018 5:04 pm
by cmhjon
Hi Klaus,

You are awesome (as usual)! It works now :)

Thank you so much,
Jon :)

Re: Download file to desktop...

Posted: Mon Apr 23, 2018 5:25 pm
by cmhjon
Me again,

Now for the next hurdle. Because the aforementioned download code is part of a preOpenStack handler, when I open a sub stack within in the project, the preOpenStack code executes which I don't want. How do I avoid this when opening a sub stack?

Thanks,
Jon

Re: Download file to desktop...

Posted: Mon Apr 23, 2018 5:28 pm
by cmhjon
Nevermind. I just added the following to each sub stack:

on preOpenStack
exit preOpenStack
end preOpenStack

That seems to have done the trick!

Thanks,
Jon

Re: Download file to desktop...

Posted: Mon Apr 23, 2018 5:55 pm
by Klaus
Hi Jon,

the trick is, to put handlers like these into the script of the first CARD and not into the stack script!
This way, they will only be executed in the stack they were meant for, and no need for "dummy" handlers anymore. :D


Best

Klaus

Re: Download file to desktop...

Posted: Mon Apr 23, 2018 6:42 pm
by dunbarx
What Klaus said.

The opposite way of looking at this, where you want to make sure that everything in a stack is fully up and running, is to place certain handlers, even though they are not card-specific, in the script of the first card to MAKE SURE that all is in place before they are executed. When the card script is examined by the engine, that stack is front and center. That happens after the stack is open, and way after preOpenWhatever.

Craig