[C#]使用ajaxFileUpload實現「檔案上傳」的功能-2(後端only)

  • 3859
  • 0
  • C#
  • 2018-01-06

C#, HttpFileCollection, web api , fileupload

    Web API的程式碼如下:

    public class FileUpLoadController : ApiController
    {
        [System.Web.Http.HttpPost]
        //GET: api/FileUpLoad/
        public string Post()
        {
            HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
            string physicalPath = "";
            if (hfc.Count > 0)
            {
                string filePath = "D:/FileUpload";
                physicalPath = filePath + "/" + hfc[0].FileName;
                hfc[0].SaveAs(physicalPath);
            }

            return "success"; 
        }
    }