How to use urlProgress
J. Landman Gay
jacque at hyperactivesw.com
Thu Jun 20 16:45:07 EDT 2013
On 6/20/13 1:08 PM, Devin Asay wrote:
> Hi folks,
>
> Maybe I'm missing something. I want to get progress information from a rather large download from an HTTP server. This is what I'm doing:
>
> command downloadFile
> set the cursor to watch
> put "http://server.com/data/myfile.gz" into tRemote_GZ
> put "/path/to/file/pwr_complete.gz" into tLocal_GZ
> put url tRemote_GZ into url ("binfile:" & tLocal_GZ)
> end downloadFile
>
> on urlProgress pURL, pStatus, pMessage, pBytesTotal
> put "Downloading " & pURL & cr & "Status: " & pStatus && pMessage && "of TotalBytes: " & pBytesTotal \
> into fld "prog"
> end urlProgress
>
> Nothing ever shows up in field "prog", but the download eventually succeeds. I can see the file on my hard drive after it has downloaded.
>
> Am I doing something wrong? I'm on OS X 10.7.x and LC 6.0.2.
It looks like the urlProgress message is only for mobile. On desktop,
here's the core of what I use:
put sURL & tFile & ".gz" into tURL
set cursor to watch
libUrlSetStatusCallback "checkStatus", (the long id of me)
set the thumbpos of sb "progressbar" to 0
put tData into url tURL
get the result
if it <> "" then answer "Could not upload file:" && it
libUrlSetStatusCallback empty -- turn it off
You turn on the status callback before the download and turn it off
afterward. My example uploads, but it works the same going the other
direction. Once the status callback is set, you'll get periodic messages
with whatever callback you assigned (in this case, the message will be
"checkStatus") and the message will be sent to the location you assigned
(in my case, the long ID of the script object.) So you need a handler to
catch the callback:
on checkStatus tURL,tStatus
put tStatus into fld "statusFld" -- might be all you need
switch
case tStatus contains "loading"
set the endvalue of sb "progressbar" to item 3 of tStatus
set the thumbpos of sb "progressbar" to item 2 of tStatus
break
case tStatus contains "uploaded"
set the thumbpos of sb "progressbar" to the endvalue of sb
"progressbar"
break
default
set the thumbpos of sb "progressbar" to 0
end switch
end checkStatus
Mine updates a progress bar, but you could just report the progress in a
text field.
--
Jacqueline Landman Gay | jacque at hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
More information about the use-livecode
mailing list