public IHttpActionResult Upload() { try { var request = Context.AuthenticatedRequest; var pollInfo = PollManager.GetPollInfo(request); if (pollInfo == null) { return(NotFound()); } if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(pollInfo.SiteId, PollUtils.PluginId)) { return(Unauthorized()); } var imageUrl = string.Empty; foreach (string name in HttpContext.Current.Request.Files) { var postFile = HttpContext.Current.Request.Files[name]; if (postFile == null) { return(BadRequest("Could not read image from body")); } var filePath = Context.SiteApi.GetUploadFilePath(pollInfo.SiteId, postFile.FileName); if (!PollUtils.IsImage(Path.GetExtension(filePath))) { return(BadRequest("image file extension is not correct")); } postFile.SaveAs(filePath); imageUrl = Context.SiteApi.GetSiteUrlByFilePath(filePath); } return(Ok(new { Value = imageUrl })); } catch (Exception ex) { return(InternalServerError(ex)); } }