FineUploader 结合 一般处理程序 【上传示例】

参考:http://www.cnblogs.com/dudu/archive/2012/11/27/fine_uploader_mvc_ajax.html  asp.net mvc示例

http://fineuploader.com/fine-uploader-demo.html  官网示例

 

需要注意的地方:webconfig里的上传文件大小限制

 一:

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength = "999999999" useFullyQualifiedRedirectUrl="true"/>
  </system.web>
</configuration>
二:
指定的文件路径要存在

HTML部分代码:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>Fine Uploader Demo</title>
    <link href="js/fineuploader.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="manual-fine-uploader">
    </div>
    <button id="triggerUpload" style="margin-top: 10px;">
        Upload now
    </button>
    <script src="js/fineuploader-3.0.js" type="text/javascript"></script>
    <script type="text/javascript">
        window.onload = function () {
            var manualuploader = new qq.FineUploader({
                element: document.getElementById("manual-fine-uploader"),
                request: {
                    endpoint: 'Handler1.ashx'
                },
                autoUpload: false,
                //multiple: false,
                validation: {
                    allowedExtensions: ['jpeg', 'jpg', 'txt'],
                    sizeLimit: 9999999 //bytes
                },
                text: {
                    uploadButton: '<i class="icon-plus icon-white"></i> Select Files'
                },
                debug: true
            });

            document.getElementById('triggerUpload').onclick = function () {
                manualuploader.uploadStoredFiles();
            };
        }
    </script>
</body>
</html>

ashx里的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.Script.Serialization;

namespace WebApplication2
{
    /// <summary>
    /// Handler1 的摘要说明
    /// </summary>

    public class Msg
    {
        public bool success { get; set; }
    }
    public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {

            context.Response.ContentType = "text/plain";
            string fileName = context.Request["qqfile"];

            using (var inputStream = context.Request.InputStream)
            {
                using (var flieStream = new FileStream(@"c:\temp\" + fileName, FileMode.Create))
                {
                    inputStream.CopyTo(flieStream);
                }
            }

            context.Response.Write(new JavaScriptSerializer().Serialize(new Msg() { success=true}));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

 

posted @ 2012-12-14 15:59  ``炯``  阅读(6240)  评论(2编辑  收藏  举报