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
Cloud Habitat Community Fine uploader download Address http://www.jb51.net/codes/70040.html
2. HTML code:
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8"/>
<title> Photo Upload-Blog Park </title>
<link href= "/css/fineuploader.css" rel= "stylesheet" >
<script src= "Http://code.jquery.com/jquery-1.8.3.min.js" ></script>
<script src= "/scripts/jquery.fineuploader-3.0.min.js" ></script>
<body>
<div id= "Jquery-wrapped-fine-uploader" ></div>
<script>
$ (function () {
$ (' #jquery-wrapped-fine-uploader '). Fineuploader ({
Request: {
Endpoint: '/imageuploader/processupload '
}
});
});
</script>
</body>
Code Description:
A) <div id= "Jquery-wrapped-fine-uploader" ></div> for displaying the upload button
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:
Copy Code code as follows:
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 chunksize = 1024 * 1024;
Public ActionResult Upload ()
{
return View ();
}
Public ActionResult Processupload (string qqfile)
{
using (var stream = Request.inputstream)
{
using (var br = new BinaryReader (stream))
{
Writestream (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 ();
}
}
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);
}
}
}
}
}
Server-side implementation of improved version
Copy Code code as follows:
Public ActionResult Processupload (string qqfile)
{
using (var InputStream = request.inputstream)
{
using (var fliestream = new FileStream (@ "c:\temp\" + Qqfile, FileMode.Create))
{
Inputstream.copyto (Fliestream);
}
}
Return Json (New {success = true});
}
Picture Upload Results Demo