• 上传文件调用webapi方式


     

     <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:文件处理操作
                        }
                    }
                }    


    另外一种方式

  • 相关阅读:
    es的多种term查询
    es的批量导入
    可重入锁
    常见的字段类型
    es中的分词
    搜索的简单使用
    application.properties中的list配置
    mysql中的concat的几个函数使用
    文档的增删改查
    Mxnet学习笔记(3)--自定义Op
  • 原文地址:https://www.cnblogs.com/sdya/p/10569585.html
Copyright © 2020-2023  润新知