Progress of a download
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Progress of a download
Hi All,
I'm follow one of the lessons here:- http://lessons.runrev.com/s/lessons/m/4 ... a-download
Just want to know how to change it so the user can be prompted to enter a download location of the file.
I'm follow one of the lessons here:- http://lessons.runrev.com/s/lessons/m/4 ... a-download
Just want to know how to change it so the user can be prompted to enter a download location of the file.
Re: Progress of a download
Hi dbailey,
simply replace the automatic saving to disk with an ask file dialog:
Best
Klaus
simply replace the automatic saving to disk with an ask file dialog:
Code: Select all
command downloadComplete pURL, pStatus
## this is the handler called when the download is finished
## the pStatus variable will show the result
## since the download is complete, there is no need to leave the progress bar visible
hide scrollbar "ProgressBar"
## check if there was a problem with the download
if pStatus = "error" or pStatus = "timeout" then
answer error "The file could not be downloaded."
else
##!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
## Ask user where to save the file, with our proposal -> desktop
ask file "Where to save the file:" with ((specialfolderpath("desktop") & "/a_pdf_file.pdf")
## IT contains the users choice:
put URL pURL into URL ("binfile:" & IT)
##!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
## open the downloaded document in the default PDF viewer just to show that it worked
launch document tFileName
## to save memory, now unload the URL from memory
## this also means that if you want to run the test again, it does not just use a cached version
unload pURL
end if
end downloadComplete
Klaus
Re: Progress of a download
Thanks again Klaus! 

Re: Progress of a download
Hi,
I ask 2 information, if I use this code with large file size (400mb) the file you download up to about 350mb then stops, as it is possible to change this? can be managed with LiveCode downloading large files.
Is possible to block the download and resume it later?
Thank you
I ask 2 information, if I use this code with large file size (400mb) the file you download up to about 350mb then stops, as it is possible to change this? can be managed with LiveCode downloading large files.
Is possible to block the download and resume it later?
Thank you
Re: Progress of a download
Hi boysky76,
Hint:
Better create a new topic next time than using and old and more or less "closed" thread!
Best
Klaus
never tried this, but it SHOULD work!boysky76 wrote:Hi,
I ask 2 information, if I use this code with large file size (400mb) the file you download up to about 350mb then stops, as it is possible to change this? can be managed with LiveCode downloading large files.
No, this is not possible with Livecode.boysky76 wrote:Is possible to block the download and resume it later?
Hint:
Better create a new topic next time than using and old and more or less "closed" thread!

Best
Klaus
Re: Progress of a download
ok sorry, next time I'll do that ...;), but downloading large files crashes like above (you have any suggestions), is a big limitation that you can not lock the file download in progress.
thanx
thanx
Re: Progress of a download
HI,
well, it should work
, sorry, no idea for a workaround.
I suggest you report this "inconvenience" to: support@runrev.com
Best
Klaus
well, it should work

I suggest you report this "inconvenience" to: support@runrev.com
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Progress of a download
At 400MBs it's probably just running out of memory.
Try changing this:
To this:
...where "DownloadComplete is the name of a handler which will be triggered when the download has completed, where you can clean up the progress bar or do any other stuff you need to do after successful completion.
With "put URL..." the entire contents are first stored in RAM and then written to disk only after completed, but with libURLDownloadToFile the download happens in chunks that are written to the local file periodically, so that relatively little of the data is in memory at a any given time.
Details on libURLDownloadToFile are in the Dictonary:
http://livecode.com/developers/api/6.0. ... oadToFile/
Try changing this:
Code: Select all
put URL pURL into URL ("binfile:" & IT)
Code: Select all
libURLDownloadToFile pURL, ("binfile:" & IT),"DownloadComplete"
With "put URL..." the entire contents are first stored in RAM and then written to disk only after completed, but with libURLDownloadToFile the download happens in chunks that are written to the local file periodically, so that relatively little of the data is in memory at a any given time.
Details on libURLDownloadToFile are in the Dictonary:
http://livecode.com/developers/api/6.0. ... oadToFile/
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Progress of a download
Oh, yes, I completely overlook that he was using:
put url into url(...)
Yes, that will make the memory blast
"liburldownloadtofile" will only load little pieces of the big file at a time!
put url into url(...)
Yes, that will make the memory blast

"liburldownloadtofile" will only load little pieces of the big file at a time!
Re: Progress of a download
so the code seems to work, but the file is not saved even if it seems downloaded, and if I try to download it another time tells me that the file can not be downloaded as if the pstatus surrendered by an error.
What could be wrong?
What could be wrong?
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Progress of a download
Here's the example given in an older set of docs at http://forums.runrev.com/posting.php?mo ... =7&t=17344
How are you checking status? Or more specifically, are you checking the data in the params passed to the callback?
Code: Select all
on mouseUp
ask file "Select a file to save to"
if it is not empty then
put it into tDestPath
put "http://www.xxxxxx.com/stuff/greatstuff.jpg" into tUrl
libUrlDownloadToFile tUrl, tDestPath, "loadDone"
end if
end mouseUp
on loadDone pUrl, pStatus
if pStatus is not "cached" then
answer "Download failed"
end if
unload url pUrl
end loadDone
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Progress of a download
Hello, thanks for the reply, your advice I have been helpful, now the download is done, only now there's another problem, I would that the file name was put automatically as already present, only the name is in httpheders and I can see it and copy it only by calling the function libUrlLastRHHeaders after downloading the file, I wish I could extrapolate first and use it in variable tname, there is a way to chiamre this url without starting the download to retrieve only the headers?