Fine Uploader (http://fineuploader.com/) is a Javascript component that implements Ajax upload files.
This project attempts to achieve a user-friendly file-uploading experience over the web. It ' s built as a Javascript plugin for developers looking to incorporate into file-uploading their.
Fine Uploader does not rely on jQuery, which means it does not reference jquery.js, and can be used normally. It also provides a jquery wrapper that can be easily integrated with jquery.
The example code in this blog post is the Fine Uploader jQuery wrapper. Look at the sample code below:
Web Front-End Implementation
1. Download jquery Plug-in Fine Uploader, download address: https://github.com/valums/file-uploader/wiki/Releases
2. HTML code:
<! DOCTYPE html>
B endpoint set the URL that the server handles the AJAX request when uploading.
3. The display effect in the browser
Server asp.net MVC Implementation code
Fine Uploader's source code uses vb.net to implement a Controller (Uploadcontroller.vb), which we changed to C # code when we used it:
Using System;
Using System.Collections.Generic;
Using System.IO;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC; Namespace CNBlogs.Upload.Web.Controllers {public class Imageuploadercontroller:controller {const int C
Hunksize = 1024 * 1024;
Public ActionResult Upload () {return View (); Public ActionResult Processupload (string qqfile) {using (var stream = Request.inputstr EAM) {using (var br = new BinaryReader (stream)) {Writest
Ream (BR, qqfile);
} return Json (new {success = true}); } private void Writestream (BinaryReader br, String fileName) {byte[] filecontents = new
Byte[] {};
var buffer = new Byte[chunksize]; while (Br. Basestream.position < Br.
BASESTREAM.LENGTH-1) { if (Br. Read (buffer, 0, chunksize) > 0) {filecontents = filecontents.concat (buffer).
ToArray ();
The using (var fs = new FileStream (@ "c:\\temp\\" + DateTime.Now.ToString ("YYYYMMDDHHMMSS") + Path.getextension (FileName).
ToLower (), FileMode.Create)) {using (var bw = new BinaryWriter (FS)) { Bw.
Write (filecontents); }
}
}
}
}
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/ajax/