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;
            }
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值