Click or drag to resize

업로드 진행 과정 출력

TABS Upload 컴포넌트는 클라이언트로 부터 업로드되는 데이터 량을 실시간으로 출력하기 위한 Progress 오브젝트를 제공합니다. 아래 예제는 업로드 진행 과정 출력의 가장 간단한 형태로 업로드 양식을 출력하는 form.asp, 업로드를 처리하는 upload.asp, 업로드 진행 과정을 출력하는 progress.asp로 구성됩니다.

form.asp

Upload 버튼 클릭시 자바 스크립트를 이용해서 업로드 진행 과정 윈도우를 띄운 후 progress.asp를 로딩시킵니다.

업로드를 처리하는 upload.asp로 ProgressID를 전달하는 방법으로 쿠키 또는 GET 파라미터를 사용할 수 있습니다.

아래 예는 GET 파라미터를 사용했습니다.

ASP
<%
Set Progress = Server.CreateObject("TABSUpload4.Progress")
'업로드 별로 진행 상태 정보를 유지하는 고유 아이디를 생성한다.
ProgressID = Progress.NewID
%>
<html>
<head>
    <title>Upload Example</title>
<SCRIPT Language="JavaScript">
function startupload() 
{
    winstyle="height=150,width=400,status=no,toolbar=no,menubar=no,location=no";
    window.open("progress.asp?progressid=<%=ProgressID%>",null,winstyle);
    '업로드 페이지에서 업로드 상태를 업데이트하기 위해 progressid를 GET 파라미터로 전달합니다.
    document.theForm.action="upload.asp?progressid=<%=ProgressID%>";
}
</script>
</head>
<body>
<form method="post" ENCTYPE="multipart/form-data" action="upload.asp" onsubmit="startupload();">
    <input type="text" name="userName">
    <input type="file" name="uploadFile">
    <input type="submit" name="submit" value="Upload">
</form>
</body>
</html>
upload.asp

Start 메서드를 호출하기 전에 QueryString(GET 파라미터)으로 전달된 ProgressID를 지정해야 업로드 데이터를 수신하면서 진행 상태를 업데이트할 수 있습니다.

ASP
<%@ LANGUAGE="VBSCRIPT" %>
<html>
<head>
    <title>Upload Results</title>
</head>
<body>
<%
Set Upload = Server.CreateObject("TABSUpload4.Upload")
'QueryString(GET 파라미터)으로 전달된 ProgressID를 지정합니다.
Upload.ProgressID = Request.QueryString("progressid")
Upload.Start "C:\Temp"
Upload.Save
%>
</body>
</html>
progress.asp

업로드 상태 정보 출력은 META 태그의 HTTP-EQUIV="Refresh" 기능을 이요해 주기적으로 페이지를 로딩시켜 구현합니다.

만일 ASP 세션을 사용한다면 업로드 중에 progress.asp 페이지가 갱신되지 않습니다. 이를 해결하기 위해서는 progress.asp 첫 머리에 EnableSessionState="False"를 명시해서 progress.asp가 현재 업로드 세션으로 부터 분리합니다.

ASP
<%@ Language=VBScript EnableSessionState="False" %>
<% 
Set Progress = Server.CreateObject("TABSUpload4.Progress")
Progress.ID = Request.QueryString("progressid")

'업로드 상태 정보를 구합니다.
Percentage = Progress.Percentage
TransferBytes = Progress.TransferBytes
TotalBytes = Progress.TotalBytes
BytesPerSec = Progress.BytesPerSec
%>
<html>
<Head>
    <title></title>
<%
    '업로드가 완료되지 않았으면 1초에 한번식 progress.asp를 갱신시켜 업로드 변화를 출력합니다.
    If Percentage < 100 Then
        Response.Write("<Meta HTTP-EQUIV=""Refresh"" CONTENT=1>")
    End If
%>
</head>
<body>
'업로드 상태 정보를 그래프 또는 텍스트 형태로 출력합니다.
......
</body>
</html>
Caution note Caution

Progress 오브젝트와 페이지 Refresh를 사용하는 위 방식의 경우 웹 서버에 많은 부하를 야기하고 웹 브라우저의 캐시 또는 프록시 서버의 캐시 정책에 따라 Refresh가 올바르게 되지 않을 수 있습니다. 정확한 진행 상태 출력과 업로드 용량 제한, 업로드 취소 등을 구현하려면 TABS Fileup4 ActiveX & Plugin을 사용해야 합니다.