开发者

asp.net ajax upload file real time progress bar not working

I am trying to do ajax file upload and real time progress bar, I have tested it in the localhost and it worked perfectly, however when I tried testing it on the online Web Server the bar didn't work up till the end of the uploading file, when I put System.Threading.Sleep(value) in the end of uploading loop, the bar worked but the uploading was very slow,

How can I resolve this?

The steps I used:

  1. Construct iframe(point to Upload.aspx) and file upload inside it.

  2. On pageload javascript function the iframe page is called with the window.parent.register(form) function that predicate the iframe form to the javascript variable in t开发者_Go百科he parent page.

  3. In the parent page (Default.aspx) I placed a button, and onclick the iframe form that was predicated is submited. Then the javascript interval calls an ajax callback function every (1000ms).

  4. This function (the ajax callback) is Watching the session["UploadInfo"].

  5. When the iframe form submits the iframe page, it calls the DoUpload() method that reads the file in the while loop from (fileUpload.PostedFile.InputStream.Read(bytes,0,1);) then writes the byte in a specific path, and adds (1) to the session["UploadInfo"] (which increases the progress bar).

  6. I want to the DoUpload and ajax callback functions to work synchronously.

  7. When I run the website in localhost every thing works exactly as I expect, but when run this from the website the progress bar does not work.

Notice: When I put System.Threading.Thread.Sleep(100) in the while loop the progress bar works, but is very slow.


Hi I found your answer while I search for a non-flash file upload solution with progress bar and file size validation.

In general, you need flash or java like applet that works with both client-side browser and server-side.

But, I am looking for the exact solution of what you have tried.

You tried good but the problem is with the implementation logic. You understood very well that Javascript cannot access local file system. So you depend on AJAX for server-side code to tell you the amount of file received/uploaded.

The asynchronous call to a file that calculates filesize is a good idea. To understand the problem you face, you need to understand the way it works.

The file upload will be made with a streamreader and streamwriter that are residing at browser-end to the filesystem at the server-side. You may also need to consider the same origin policy which is very important for multiple AJAX request to the server.

By the HTTP 1.1 specification, any browser will throw only 2 parallel connections to the server at the same time. In other words, only 2 resources can be downloaded from the same domain name.

Please check with these options and post your reply. Better go for a component. I am using obout File uploader (http://www.obout.com/Obout.Ajax.UI/FileUpload/). I work very well for many years. Now I need a flash less component as per my customer requirement. Otherwise it is the best ASP.NET component I used for File Upload.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜