Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 956
Product
FileUp
Version
all
Title
Progress Indicator and transfer rates
Problem
Does FileUp's Progress Indicator have a built-in way to show transfer rates?
Solution

FileUp's Progress Indicator does not have any built-in way to show transfer rates for the current transfer. However, we have come up with a modification to the Progress Indicator sample that estimates the current rate of transfer and average rate of transfer (in bytes per second).

The code below is a replacement for the progress.asp file that comes with the Progress Indicator ASP QueryString sample. The Progress Indicator sample is installed with FileUp and can be found on your local machine here at: http://localhost/SAFileUpSamples/br> (This modified progress.asp file can also be downloaded from the Attachments section below.)

progress.asp

<%@ Language=VBScript EnableSessionState="False" %> 
<% 
'-----------------------------------------------------------------------
'--- This is the progress indicator itself.  It refreshes every second
'--- to re-read the file progress properties, which are updated thoughout
'--- the upload.
'-----------------------------------------------------------------------
'--- Declarations
Dim oFileUpProgress
Dim intProgressID
Dim intPercentComplete
Dim intBytesTransferred
Dim intTotalBytes
Dim bDone

intPercentComplete = 0 intBytesTransferred = 0 intTotalBytes = 0
'--- Instantiate the FileUpProgress object Set oFileUpProgress = Server.CreateObject("Softartisans.FileUpProgress")
'--- Set the ProgressID with the value we submitted from the form page oFileUpProgress.ProgressID = CInt(Request.QueryString("progressid"))
'--- Read the values of the progress indicator's properties intPercentComplete = oFileUpProgress.Percentage intBytesTransferred = oFileUpProgress.TransferredBytes intTotalBytes = oFileUpProgress.TotalBytes
'--- BEGIN CUSTOM RATE OF TRANSFER CODE Dim intTimeInterval Dim intTotalElapsedTime Dim intBytesTransAsOfLastInterval Dim intBytesTransDuringInterval Dim intCurrentBytesPerSecond Dim intAverageBytesPerSecond
'--- Set interval (in seconds) for which progress indicator will refresh intTimeInterval = 1
'--- Add one interval to the elapsed time If IsEmpty(Application(oFileUpProgress.ProgressID & "intTotalElapsedTime")) Then intTotalElapsedTime = 0 Else intTotalElapsedTime = Application(oFileUpProgress.ProgressID & "intTotalElapsedTime") + intTimeInterval End If
'--- Read total bytes transferred during last Interval this from Application object intBytesTransAsOfLastInterval = Application(oFileUpProgress.ProgressID & "intBytesTransAsOfLastInterval")
'--- Calculate bytes transferred during last Interval intBytesTransDuringInterval = intBytesTransferred - intBytesTransAsOfLastInterval
'--- Calculate bytes per second for last Interval intCurrentBytesPerSecond = intBytesTransDuringInterval / intTimeInterval
'--- Calculate average bytes per second If intTotalElapsedTime > 0 Then intAverageBytesPerSecond = intBytesTransferred / intTotalElapsedTime Else intAverageBytesPerSecond = 0 End If
'Save values in Application object that we need to access in the future Application(oFileUpProgress.ProgressID & "intTotalElapsedTime") = intTotalElapsedTime Application(oFileUpProgress.ProgressID & "intBytesTransAsOfLastInterval") = intBytesTransferred
'If transfer complete, destroy Application objects If oFileUpProgress.TransferComplete = True Then Set Application(oFileUpProgress.ProgressID & "totalElapsedTime") = Nothing Set Application(oFileUpProgress.ProgressID & "intBytesTransAsOfLastInterval") = Nothing End If
'--- END CUSTOM RATE OF TRANSFER CODE
%> <html> <Head> <% '--- If the upload isn't complete, continue to refresh If intPercentComplete < 100 Then bDone = False Response.Write("<Meta HTTP-EQUIV=""Refresh"" CONTENT=" & intTimeInterval & ">") Else bDone = True End If %> </head> <Body> <TABLE border=1> <TR> <TD colspan=3><B>FileUp Progress Indicator</B></TD> <TD colspan=2><B>Status: <%If bDone Then Response.Write("Complete!") Else Response.Write("Sending") End If%></B> </TR> <TR><TD>Progress ID </TD> <TD>Graphic Indicator</TD> <TD>Transferred Bytes</TD> <TD>Total Bytes</TD> <TD>Transferred Percentage</TD> </TR> <TR><TD align=left><%=oFileUpProgress.progressid%></TD> <TD> <TABLE border=1 cellspacing=0 ALIGN="left" WIDTH="<%=intPercentComplete%>%"> <TR> <TD align=right width="100%" BGCOLOR="blue"><B><%=intPercentComplete%>%</B></TD> </TR> </TABLE> <% Response.Write("</TD>") Response.Write "<TD align=center>" & intBytesTransferred & "</TD>"
if oFileUpProgress.totalbytes > 0 then Response.Write("<TD align=center>" & intTotalBytes & "</TD>" & _ "<TD align=center>" & intPercentComplete & "%</TD>" ) else Response.Write ("<TD align=center>" & "N/A" & "</TD>" & _ "<TD align=center>" & "N/A" & "</TD>") end if Response.Write("</TR>")
%> </TABLE> <p>Elapsed time: <%=intTotalElapsedTime%> seconds<br> Current rate of transfer: <%=intCurrentBytesPerSecond%> Bytes / second<br> Average rate of transfer: <%=Int(intAverageBytesPerSecond)%> Bytes / second</p> </Body> </Html>

In addition to using the code above for the Progress Indicator page, you may need to increase the height of the window the Progress Indicator is loaded in. You can do this by modifying the JavaScript that opens this window from the page that initiates the file transfer. In our Progress Indicator Sample that comes with FileUp, this page is form.asp. An example of this code is:

Snippet of form.asp

function startupload() {
     winstyle="height=200,width=500,status=no,toolbar=no,menubar=no,location=no";
     window.open("progress.asp?progressid=<%=intProgressID%>",null,winstyle);
     document.theForm.action="savefile.asp?progressid=<%=intProgressID%>";
}
Attachments
Attachments/KB956_files1.zip
Created : 10/29/2004 3:43:33 PM (last modified : 4/24/2012 4:28:59 PM)
Rate this article!
Comments