Receive images uploaded by the mobile side, sample code:
[HttpPost] [Apisecurityfilter] PublicIhttpactionresult uploadimg () {stringIMGs =""; Try{System.Web.HttpFileCollection Files=System.Web.HttpContext.Current.Request.Files; foreach(stringKeyinchfiles. AllKeys) {System.Web.HttpPostedFile file=Files[key]; if(!string.isnullorempty (file. FileName) {stringFilePath ="/upload/images/"+datetime.now.tostring ("yyyymm") +"/"; stringDIR =System.Web.HttpContext.Current.Server.MapPath (FilePath); if(!directory.exists (dir)) Directory.CreateDirectory (dir); stringOldname =file. FileName; stringext = oldname.substring (Oldname.lastindexof (".")); stringNewName = DateTime.Now.ToString ("ddhhmmssfff") +ext; stringurl = filePath +NewName; File. SaveAs (dir+newName); IMGs+="website"+ URL +","; } } //Add, update to database } Catch(Exception ex) {Log.error ("========= Upload image error:"+ ex. Message +"============="); returnJson (New{Result ="fail", Response =Ex. Message}); } returnJson (New{Result ="OK", Response = IMGs. TrimEnd (',') }); }
ASP. NET WEB API related