How to implement Ajax file upload with fine uploader+asp.net MVC

Source: Internet
Author: User
Tags file upload min wrapper

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/

Related Article

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.