zoukankan      html  css  js  c++  java
  • 文件上传之Html5 + jQuery上传、asp.net web api接收

    HTML:

      <div>
            <label for="fileUpload">
                选择文件
            </label>
            <br/>
            <input id="fileUpload" type="file" multiple="multiple" />
            <br />
            <input id="btnUploadFile" type="button" value="上传文件" />
        </div>

    js:

    $("#btnUploadFile").on("click", function () {
                    var data = new FormData(); 
                    var files = $("#fileUpload").get(0).files;
                    if(files.length > 0){
                        for (var i = 0; i < files.length;i++){
                            data.append(i.toString(), files[i]);
                        }
                    }
    
                    $.ajax({
                        type: "post",
                        url: "http://localhost:7247/api/fdfs/upload",
                        contentType: false,
                        cache: false,
                        currentType: false,
                        processData: false,
                        data: data,
                        success: function (res) {
                            alert(res);
                        }
                    });
                });

    WebAPI:

             if(HttpContext.Current.Request.Files.AllKeys.Any())
                {
                    var httpPostedFile = HttpContext.Current.Request.Files;
                    if(httpPostedFile != null && httpPostedFile.Count > 0)
                    {
                        foreach (string f in httpPostedFile)
                        {
                            var file = httpPostedFile[f];
                            //Todo:文件处理操作
                        }
                    }
                }    
  • 相关阅读:
    mouseOver与rollOver
    排序二叉树
    发展
    bitmapData
    回调与事件
    遍历舞台上所有对象
    面向对象原则
    面向对象的三大特征(个人理解)
    面向对象出现原因以及意义
    OC语言BLOCK和协议
  • 原文地址:https://www.cnblogs.com/guokun/p/5843692.html
Copyright © 2011-2022 走看看