进度指示器采用FileUpload控件 [英] Progress Indicator With FileUpload control
问题描述
我有一个网页,我希望人们能够上传内容。 (只会有一小部分人数量使用它,因为它是访问的限制,所以我不太担心任何DOS类型的攻击。)
I have a web page which I want people to be able to upload content to. (There will only be a small number of people using it, as it is access restricted, so I'm not too worried about any DOS type attacks.)
我使用一个FileUpload控件做到这一点:
I'm using a fileUpload control to do this:
protected void Button1_Click(object sender, EventArgs e)
{
if (fileUploader.HasFile)
try {
fileUploader.SaveAs(Server.MapPath("Uploads\\") + fileUploader.FileName);
errorMessage.Text = "File name: " +
fileUploader.PostedFile.FileName + "<br>" +
fileUploader.PostedFile.ContentLength + " kb<br>";
}
catch (Exception ex) {
errorMessage.Text = "ERROR: " + ex.Message.ToString();
}
else
{
errorMessage.Text = "You have not specified a file.";
}
}
该文件可以达到50MB(我已经改变了web.config中允许此)。我的问题是,随着大型文件的用户无法看到的上传的进展。
The files can be up to 50MB (I have changed the web.config to allow this). The problem I have is that with large files the user can't see the progress of the upload.
我想知道我怎么能在页面上显示进度,使用户可以看到正在发生的事情。没有大惊小怪任何幻想 - 只要是这样的:
I want to know how I can display the progress on the page so the user can see something is happening. Not fussed about anything fancy - just something like:
的字节上传/总字节数的
就可以了。我可以用postedFile.ContentLength得到的总字节数,但不知道如何获得字节上传
would be fine. I can get the total bytes using postedFile.ContentLength, but don't know how to get the bytes uploaded.
此外 - 我能够刷新屏幕上传正在发生
Also - am I able to refresh the screen as the upload is taking place?
干杯,
本
推荐答案
这答案不是特定于ASP ...
This answer is not specific to ASP...
一个文件上传通常是通过一个 HTTP POST
要求与内容类型做>。这包括在请求体的部分中的一个的文件主体。
A file upload is typically done by making an HTTP POST
request with Content-type: multipart/form-data
. This includes the file body in one of the parts of the request body.
因此,一个特定的浏览器选项卡中,只能有在给定时间一个页面加载。简短的回答是,除非你是iframe(一个状态,一个用于上传),您将无法显示状态。真正看中
So within a given browser tab, there can only be one page loading at a given time. The short answer is, unless you get really fancy with iframes (one for status, one for upload), you will not be able to show the status.
然而,如果使用闪光灯,你可以。 http://www.uploadify.com/ 是一个伟大的小前端插件(jQuery的),它允许用户可以选择多个文件,并上传所有这些,显示沿途的状态。我只是它插入限制上传到64M的网站。工程真棒。
However, if you use Flash, you can. http://www.uploadify.com/ is a great little front-end plugin (for jQuery) which allows the user to select multiple files, and uploads them all, showing the status along the way. I just plugged it into a site that limits uploads to 64M. Works awesome.
这篇关于进度指示器采用FileUpload控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!