我正在使用以下代码从我的ftp服务器下载文件。该文件在移动设备上下载。 我尝试使用进度条显示下载的数据量 问题是我总是“缓存”。 这是我的代码
constant FTPHOST = "myIp"
constant FTPUSER = "user"
constant FTPPASS = "password"
global sDownloadStart
on mouseUp
put "test.zip" into tFileName
put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST & "/" & tFileName into pUrl
-- start the download process, telling Rev to call the "downloadComplete" handler when finished
Load URL pUrl with message "urlProgress"
set the startvalue of sb "progressbar" to 0
end mouseUp
on urlProgress pURL, pStatus, pBytesDone, pBytesTotal
put pStatus into fld "pf1"
switch item 1 of pStatus
case "loading"
set the thumbPosition of sb "Progressbar" to round((pBytesDone / pBytesTotal) * 100)
put the round of (item 1 of pBytesDone / 1024)&& "KB Downloaded" into field "status"
break
case "cached"
-- if pStatus is "cached" then
-- work out a file name for saving this file to the desktop
set the itemDel to slash
put "binfile:" & specialfolderpath("documents") & "/test.zip" into myPath
//put "data.file" into tFileName
put url pUrl into url myPath
answer "Download completed" with ok
-- 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
break
case "error"
if pStatus = "error" or pStatus = "timeout" then
answer error "The file could not be downloaded." with "ok"
end if
break
end switch
end urlProgress
答案 0 :(得分:1)
在加载URL完成后调用您的urlProgress
处理程序。要获得不同的状态,您必须拨打另一条消息或以不同的方式呼叫消息,例如
on mouseUp
//delete URL "binfile:" & specialfolderpath("documents") & "/data.file"
put "data.file" into tFileName
put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST & "/" & tFileName into pUrl
-- start the download process, telling Rev to call the "downloadComplete" handler when finished
// the callback message has only 2 parameters: url and urlStatus
Load URL pUrl with message "downloadComplete"
send "urlProgress pUrl" to me in 200 millisecs
end mouseUp
on urlProgress pUrl //,pStatus, pMessage,pbytesR,pbytesT
put urlStatus(pUrl) into pStatus
if item 1 of pUrl is "loading" then
put item 2 of pStatus into pBytesR
put item 3 of pStatus into pbytesT
put item 1 of pStatus into pStatus
send "urlProgress pUrl" to me in 200 millisecs
end if
end urlProgress
on downloadComplete theUrl,theUrlStatus
if theUrlStatus is "cached" then
-- work out a file name for saving this file to the desktop
set the itemDel to slash
put "binfile:" & specialfolderpath("documents") & "/data.file" into myPath
put "data.file" into tFileName
put url theUrl into url myPath
answer "Download completed" with ok
-- 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
-- check if there was a problem with the download
if pStatus = "error" or pStatus = "timeout" then
put libUrlErrodData(theUrl) into myErr
answer error "The file could not be downloaded."&& myErr with "ok"
end if
end downloadComplete
让我知道这是否有效(应该)。如果没有,我会再看看。