简体   繁体   English

实时进度栏ASP.net

[英]Real Time Progress Bar ASP.net

I am uploading Large Video files on Amazon S3, I have to display progress bar while uploading. 我正在Amazon S3上上传大型视频文件,上传时必须显示进度栏。 I am showing progress bar using javascript,but its not real time,for eg if I upload 3 MB video, it shows progress properly(ie 100%) then upload video(However in real,it uploads video while displaying the progress bar) This works fine for small videos,but when I upload videos more then 8MB, it show progress till 100% properly,while browser status(Left most Corner) shows 50% progress. 我正在使用javascript显示进度条,但它不是实时的,例如,如果我上载3 MB视频,它会正确显示进度(即100%),然后再上载视频(但是实际上,它在显示进度条的同时上载视频)对于小型视频效果很好,但是当我上传大于8MB的视频时,它会显示进度,直到100%正确为止,而浏览器状态(最左侧)显示进度为50%。 This is how I am doing 我就是这样

 var size = 2;
  var id = 0;
            function ProgressBar() {
            if (document.getElementById('<%=FileVideoUpload.ClientID %>').value != "") {
                document.getElementById("divProgress").style.display = "block";
                document.getElementById("divUpload").style.display = "block";
                document.getElementById("fakebtn").style.display = "block";
                document.getElementById('<%=btnupload.ClientID %>').style.display = "none";
                id = setInterval("progress()", 250);
                return true;
            }
            else {
                alert("Select a file to upload");
                return false;
            }

        }

        function progress() {
            size = size + 1;
            if (size > 299) {
                clearTimeout(id);
            }
            document.getElementById("divProgress").style.width = size + "pt";
            document.getElementById("<%=lblPercentage.ClientID %>").firstChild.data = parseInt(size / 3) + "%";
            document.getElementById("<%=FileVideoUpload.ClientID %>").disabled = true;
            if (parseInt(size / 3) == 100) {
                document.getElementById("updstatus").innerHTML = "Please Wait..";
            }
        }


 <asp:FileUpload ID="FileVideoUpload" runat="server" />&nbsp;<br />
        <br />
        <asp:Button ID="btnupload" runat="server" Text="Upload" OnClientClick="return ProgressBar()"
            OnClick="btnupload_Click" />
        <input type="button" value="Upload" id="fakebtn" style="display: none" />
        <br />
        <br />
        <div id="divUpload" style="display: none">
            <div style="width: 300pt; text-align: center;" id="updstatus">
                Uploading...</div>
            <div style="width: 300pt; height: 20px; border: solid 1pt gray">
                <div id="divProgress" style="width: 1pt; height: 20px; background-color: Gray; display: none">
                </div>
            </div>
            <div style="width: 300pt; text-align: center;">
                <asp:Label ID="lblPercentage" runat="server" Text="Label"></asp:Label></div>
        </div>

and on my btnupload_Click, I am doing this before uploading 在我的btnupload_Click上,我正在执行此操作,然后再上传

System.Threading.Thread.Sleep(8000);

How can I display real progress of file upload? 如何显示文件上传的实际进度?

As per the file upload concern, you cant really do ajax uploads. 根据文件上传的注意事项,您不能真正执行Ajax上传。 but there are few possiblities 但是可能性很小

  1. Use HTML5 file api : File Api 使用HTML5文件api: File api
  2. Use third party library to monitor the progress bars. 使用第三方库监视进度条。 Jquery ajax file upload plugin jQuery Ajax文件上传插件

Hope this helps you to get started. 希望这可以帮助您入门。

you might wanna take a look at File upload and Progress events with HTML5 XmlHttpRequest Level 2 您可能想看一下HTML5 XmlHttpRequest Level 2的文件上传和进度事件

Hope that can help you. 希望能对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM