Google Code Prettify

[WebAPI]以WebAPI的POST方法上傳檔案的參考範例


public IHttpActionResult Post(UploadFileInfo fi) {
 string dir = HttpContext.Current.Server.MapPath("~/Upload");
 using(FileStream fileStream = new FileStream(
     Path.Combine(dir, fi.FileName), 
     FileMode.OpenOrCreate, 
     FileAccess.Write)) {
  fileStream.Write(fi.FileContent, 0, fi.FileContent.Length);
 }
 return Ok(dir);
}