Download file to desktop...

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
cmhjon
Posts: 175
Joined: Tue Aug 04, 2015 11:55 am

Download file to desktop...

Post by cmhjon » Mon Apr 23, 2018 3:44 pm

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 :)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Download file to desktop...

Post by dunbarx » Mon Apr 23, 2018 3:53 pm

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

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Download file to desktop...

Post by Klaus » Mon Apr 23, 2018 3:58 pm

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

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Download file to desktop...

Post by bogs » Mon Apr 23, 2018 4:55 pm

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
Image

cmhjon
Posts: 175
Joined: Tue Aug 04, 2015 11:55 am

Re: Download file to desktop...

Post by cmhjon » Mon Apr 23, 2018 5:04 pm

Hi Klaus,

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

Thank you so much,
Jon :)

cmhjon
Posts: 175
Joined: Tue Aug 04, 2015 11:55 am

Re: Download file to desktop...

Post by cmhjon » Mon Apr 23, 2018 5:25 pm

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

cmhjon
Posts: 175
Joined: Tue Aug 04, 2015 11:55 am

Re: Download file to desktop...

Post by cmhjon » Mon Apr 23, 2018 5:28 pm

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

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Download file to desktop...

Post by Klaus » Mon Apr 23, 2018 5:55 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Download file to desktop...

Post by dunbarx » Mon Apr 23, 2018 6:42 pm

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”