mobile download file
Posted: Fri Nov 14, 2014 2:00 pm
i am using the bellow code to download a file from my ftp server.
On the mac desktop is working ok without problems,but in the apple simulator and in the android (phone Z1) i don't get anything..
No messages,no download,nothing and the field and progress bar don't show up.
On the mac desktop is working ok without problems,but in the apple simulator and in the android (phone Z1) i don't get anything..
No messages,no download,nothing and the field and progress bar don't show up.
Code: Select all
constant FTPHOST = "myip"
constant FTPUSER = "user"
constant FTPPASS = "pass"
global sDownloadStart
on mouseUp
put "data.sqlite" into tFileName
put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST & "/" & tFileName into myUrl
-- set up a message to show the status of the download as it progresses
libURLSetStatusCallback "showProgress", the long name of me
-- make sure the progress bar is hidden, as this property is used to initialise it
hide scrollbar "ProgressBar"
put empty into fld "ProgressField"
put the seconds into sDownloadStart
-- start the download process, telling Rev to call the "downloadComplete" handler when finished
load URL myUrl with message "downloadComplete"
end mouseUp
command showProgress pURL, pStatus
-- this is the status callback message which gets called regularly during the download
-- pStatus will show some initialisation messages, then
-- loading,bytesReceived,bytesTotal
-- using a graphical progress bar instead
-- ths first time this is called, find the total number of bytes that are to be downloaded
-- use this info to set the span of the progress bar
-- wait until the download info is being received
if the number of items in pStatus = 3 then
if the visible of scrollbar "Progressbar" = false then
put the last item of pStatus into tTotalBytes
set the startValue of scrollbar "Progressbar" to 0
set the endValue of scrollbar "Progressbar" to tTotalBytes
show scrollbar "Progressbar"
end if
set the thumbPosition of scrollbar "Progressbar" to item 2 of pStatus
end if
-- better text information
if the number of items in pStatus = 3 then
put item 2 of pStatus into tBytesReceived
put item 3 of pStatus into tTotalBytes
-- this gives very large numbers that are not easily read, so convert to KB
put tBytesReceived div 1024 into tKBreceived
put tTotalBytes div 1024 into tTotalKB
-- calculate speed
put the seconds - sDownloadStart into tElapsedSeconds
if tElapsedSeconds = 0 then
-- make sure we don't divide by zero at the start
put "unknown" into tKBperSecond
else
put round(tKBreceived / tElapsedSeconds, 1) into tKBperSecond
end if
--put "Received " & tKBreceived & " KB of " & tTotalKB & " KB at " into fld "ProgressField"
put "Received " & tKBreceived into fld "ProgressField"
//put tKBperSecond & " KB/sec" after fld "ProgressField"
end if
end showProgress
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
-- work out a file name for saving this file to the desktop
set the itemDel to slash
put "binfile:" & specialfolderpath("documents") & "/data.sqlite" into myPath
put url purl into url myPath
answer "Download completed" with ok
put empty into fld "ProgressField"
dispatch "ResetList" to group "datagrid1" of group "scroller1" of card "base"
-- 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