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";
}
}