BootStrap ProgressBar Implementation of a large file upload progress bar instance code _javascript tips

Source: Internet
Author: User
Tags file upload file upload progress bar

1. First to achieve large file upload , if it is a few megabytes or a few 10 trillion files on the basic upload method can be, but if it is a large file upload is the best way to upload a fragment. I am here mainly to use at the client side of the fragment read to the server segment, and then save, to the server segment after reading the fragmented data will be combined.

2. The front end code is as follows:

<%@ Page language= "C #" autoeventwireup= true "codebehind=" UploadTest2.aspx.cs "inherits=" Html5uploadtest.uploadtest2 "%>  

3. The background general handler is as follows:

Using System;
Using System.Collections.Generic;
Using System.IO;
Using System.Linq;
Using System.Web; namespace Html5uploadtest {///<summary>///Summary description for Upload///</summary> public class Uploa D:ihttphandler {public void ProcessRequest (HttpContext context) {context.
Response.ContentType = "Text/plain"; try {//Take parameters from request, note that the uploaded file is in Requst.files string name = Context.
request["Name"]; int total = Convert.ToInt32 (context.
request["Total"]); int index = Convert.ToInt32 (context.
request["index"]); var data = context.
request.files["Data"]; Save a fragment to disk string dir = context.
Request.mappath ("~/temp");
string file = Path.Combine (dir, name + "_" + index); Data.
SaveAs (file); If it is the last fragment, the combination//Of course, you can also use other methods, such as the receipt of each fragment directly to the corresponding location of the final file, but to control concurrency to prevent file lock conflicts if (index = = total) {file = Path.Combine (dir, name
);
byte[] bytes = NULL; using (FileStream fs = new FileStream (file, FileMode.OpenOrCreate)) {for (int i = 1; I <= total; ++i) {String part = Path.Combine (dir, name + "_ "+ i);
bytes = System.IO.File.ReadAllBytes (part); Fs. Write (bytes, 0, bytes.
Length);
bytes = NULL;
System.IO.File.Delete (part); Fs.
Close ();
Exception {throw}//return succeeded, simplified processing//return Json (new {Error = 0}) is done here;
public bool IsReusable {get {return false;}}} }

4. Of course, the backstage also need some abnormal processing or power transmission of the work to do, to be continued ...

The above is a small set to introduce the bootstrap ProgressBar to achieve large file upload progress bar Instance code, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.