Download file to desktop...
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Download file to desktop...
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
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
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Download file to desktop...
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
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...
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
You want something like;
Best
Klaus
"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
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
Klaus
Re: Download file to desktop...
Well, if I understood the question correctly (always possibly did not )
I would think this should work (I don't have a webserver/filename to test at the moment)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.
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...
Hi Klaus,
You are awesome (as usual)! It works now
Thank you so much,
Jon
You are awesome (as usual)! It works now
Thank you so much,
Jon
Re: Download file to desktop...
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
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...
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
on preOpenStack
exit preOpenStack
end preOpenStack
That seems to have done the trick!
Thanks,
Jon
Re: Download file to desktop...
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.
Best
Klaus
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.
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Download file to desktop...
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
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