webapi 带参数上传图片

来源:互联网 发布:程序员三强 编辑:程序博客网 时间:2024/05/17 00:08
  1. public IHttpActionResult getTest2()  
  2.         {  
  3.   
  4.             string id=HttpContext.Current.Request["id"];  
  5.             string name = HttpContext.Current.Request["name"];  
  6.             HttpFileCollection files = HttpContext.Current.Request.Files;  
  7.   
  8.             foreach (string key in files.AllKeys)  
  9.             {  
  10.                 HttpPostedFile file = files[key];//file.ContentLength文件长度  
  11.                 if (string.IsNullOrEmpty(file.FileName) == false)  
  12.                     file.SaveAs(HttpContext.Current.Server.MapPath("~/App_Data/") + file.FileName);  
  13.             }  
  14.   
  15.             return Ok("success2");  
  16.         }  
原创粉丝点击