【ASP .NET MVC】POSTで画像アップロード
はい、前回に引き続き今度はサーバー側です。
ASP .NET MVCのWeb APIで画像を受け取りますよー
以下コントローラーです。
using System; using System.Collections.Generic; using System.Net.Http; using System.Web; using System.Web.Http; public class UploadPhotoController : ApiController { [HttpPost] public HttpResponseMessage Post() { var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { var postedFile = httpRequest.Files[file]; var filePath = HttpContext.Current.Server.MapPath("~/" + postedFile.FileName); postedFile.SaveAs(filePath); } return Request.CreateResponse(200, new object()); } }