webapi接收上传的文件和相关参数

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/lxrj2008/article/details/56845075
[HttpPost]
        public IHttpActionResult TestPostFile()
        {
            string name = HttpContext.Current.Request["name"];
            string age = HttpContext.Current.Request["age"];
            string name1 = HttpContext.Current.Request.Params["name"];
            string age1 = HttpContext.Current.Request.Params["age"];
            HttpFileCollection files = HttpContext.Current.Request.Files;
            foreach (string key in files.AllKeys)
            {
                HttpPostedFile file1 = files[key];
                if (string.IsNullOrEmpty(file1.FileName) == false)
                    file1.SaveAs(HttpContext.Current.Server.MapPath("~/App_Data/") + file1.FileName);
            }  
           return Ok("success2");  
        }




展开阅读全文

没有更多推荐了,返回首页