1. Pertama, terapkan unggahan file besar . Jika beberapa megabyte atau lusinan megabyte, gunakan metode unggahan dasar, tetapi jika itu adalah unggahan file yang besar, yang terbaik adalah menggunakan unggahan beling. Di sini saya terutama menggunakan klien untuk membaca data bercukur ke segmen server, dan kemudian menyimpannya. Setelah segmen server dibaca, data bercukur digabungkan.
2. Kode front-end adalah sebagai berikut:
< %@ Page language = "c#" autoeventwireup = "true" codebehind = "unggahtest2.aspx.cs" mewariskan = "html5uploadtest.uploadtest2" %> <html lang = "zh-cn"> <head> <meta charset = "utf-8"> <titchments> <-title> Contoh headle <head> <meta charset = "utf-8"> <judul> <-judul> Contoh headle <head> <head> <meta charset = "utf-8"> <judul> <-judul> Contoh HEADL5 of src = "Scripts/jQuery-1..8.2.js"> </script> <link href = "bootstrap-progressbar/bootstrap-progressbar-3.3.4.css" rel = "stylesheet"/<skrip src = "bootstrap-progressbar/bootstrap-prograpse.scrip <cript scrip =" BootStrap-—kripsbar/bootstrap/bootstrap/bootstrap/bootstrap/bootstrap/bootstrap/bootstrap/bootstrap/bootstrap/bootstrap/bootstrap/bootstrap/bootstrap/bootstrap/bootstrap/bootstrap/bootstrap href = "jqueryui/jquery-ui.css" rel = "stylesheet"/> <script src = "jqueryui/jquery-ui.js"> </script>-%> <script> function unggah () {$ ("#unggah"). attr ("script> DISABLED (" DISABLED () {$ ("#Upload"). ATR ("DISABLED", "DISABLED (" DISABLED ("DISABLED"). $ ("#file") [0] .files [0], // File objek filenum = $ ("#file") [0] .files [0] .length, name = file.name, // nama file ukuran = file.size, // ukuran total succeed = 0; var shardsize = 2 * 1024 * 1024, // shard shard = 0; var shardsize = 2 * 1024 * 1024, // shard shard = 0; var shardsize = 2 * 1024 * 1024, // shard shard = 0; var shardsize = 2 * 1024 * 1024, / /shard shard = 0; var shardsize = 2 * 1024 * 1024, / /shard shard = 0; var shardsize = 2 * 1024 * 1024, / /shard sharder = var shardsize = 2 * 1024 * 1024, / /shard shardcor = MATH. // Jumlah total irisan $ ('. Kemajuan .progress-bar'). Attr ('data-transitionGoal', 0) .progressbar ({display_text: 'isi'}); untuk (var i = 0; i <shardcount; ++ i) {// Hitung posisi awal dan akhir dari setiap slice vari start = i shards; i * sHARDS =//MATHIN = MATHIN, KONSURE = POSIT MATHING, MATHING, AKHIRE, AKHIRE, AKHIRE, AKHIRE, AKTIZE, AKHIRE, AKHIRE, AKHIRE, UKSIRE, AKHIRE, UKSIRE, AKHIRE, UKSIRE (I. Formulir, formdata adalah bentuk var baru yang ditambahkan ke html5. = formdata baru (); form.append ("data", file.slice (start, end)); // Metode Slice digunakan untuk memotong bagian dari file form.append ("name", name); Form.Append ("Total", Shardcount); // Jumlah total irisan Form.Append ("index", i + 1); // Jumlah irisan saat ini adalah // AJAX mengirimkan $ .AJAX ({url: "unggah.ashx", ketik: "post", data: form, async: true, // async ProcessData: false, // sangat penting untuk memberi tahu jQuery untuk memproses konten yang benar: false, // Ini sangat penting untuk spesifik {++ Succeed; $ ("#output"). Teks (SUCCECED + " /" + SHARDCOUNT); var persen = ((SUCCECED / SHARDCOUNT) .TOFIXED (2)) * 100; UpdateProgress (Persen); if (SUCCECED == shardcount) {$ ("#unggah"). progress (persen, $ element) {var progressBarwidth = persen * $ element.width ()/100; $ element.find ('div'). animate ({width: progressBarwidth}, 500) .html (persen + "%");} // $ (dokumen) .eady (function () {/persen + "%") .day. 'Isi'}); //}); function updateProgress (persentase) {$ ('. Kemajuan .progress-bar'). attr ('Data-TransitionGoal', Persentase) .progressBar ({display_text: 'fill'});} </script> </head> <body> <input type = "}}); OnClick = "unggahfile ();"> Unggah </button> <span id = "output" style = "font-size: 12px"> tunggu </span> <div> <div id = "progressBar" role = "progressBar" data-transitiongoal = ""> </Div> </div> </body> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html>3. Prosedur pemrosesan latar belakang umum adalah sebagai berikut:
menggunakan sistem; menggunakan System.collections.generic; menggunakan System.io; menggunakan System.linq; menggunakan System.web; namespace html5uploadtest {/// <summary> /// ringkasan deskripsi ringkasan untuk unggah /// </ringkasan> unggah kelas publik: contextphandler. "Teks/Polos"; coba {// Pilih parameter dari permintaan, perhatikan bahwa file yang diunggah adalah string dalam name request.files = context.Request ["name"]; int total = convert.toint32 (context.request ["Total"]; int index = convert.toint32 (context.Request ["]; var a." disk string dir = context.Request.MapPath("~/temp");string file = Path.Combine(dir, name + "_" + index);data.SaveAs(file);//If it is already the last shard, combine//Of course you can also use other methods such as directly writing to the corresponding location of the final file when receiving each shard, but you must control the concurrency to prevent file lock conflicts if (index == total) {file = path.combine (dir, name); // byte [] bytes = null; menggunakan (filestream fs = filestream baru (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. null; system.io.file.delete (bagian); fs.close ();}}}}} catch (exception) {throw;} // kembalikan apakah itu berhasil, pemrosesan yang disederhanakan dilakukan di sini // return json (baru {error = 0});} public bool yang dapat dibreusable {get {return false;4. Tentu saja, latar belakang juga membutuhkan beberapa penanganan pengecualian atau pemadaman listrik dan transmisi untuk dilanjutkan. . .
Di atas adalah contoh kode bootstrap progressbar yang saya perkenalkan kepada Anda. Saya harap ini akan membantu Anda. Jika Anda memiliki pertanyaan, silakan tinggalkan saya pesan dan editor akan membalas Anda tepat waktu. Terima kasih banyak atas dukungan Anda ke situs web Wulin.com!