public IActionResult PostUpLoadPhoto([FromBody] UploadImgModel uploadImgModel) { var auth = HttpContext.AuthenticateAsync(); var userIdstr = auth.Result.Principal.Claims.First(t => t.Type.Equals(ClaimTypes.NameIdentifier))?.Value; if (!uint.TryParse(userIdstr, out uint userId)) { return(BadRequest(new { messager = "权限查找失败,ID解析失败=" + userId })); } if (uploadImgModel.File == null || uploadImgModel.File.Length <= 0) { return(BadRequest(new { messager = "收到的文件为空" })); } byte[] fileBytes = Convert.FromBase64String(uploadImgModel.File); var result = PhotoManager.Instance.UploadNewPhoto(fileBytes, uploadImgModel.PhotoAlbumId, userId, uploadImgModel.Name); if (result == "") { var user = UserInfoManager.Instance.GetUserInfo(userId); var albumInfo = PhotoManager.Instance.GetPhotoAlbumdata(uploadImgModel.PhotoAlbumId); AlbumInfoModel albumInfo2 = new AlbumInfoModel(albumInfo, user != null ? user.Username : ""); return(Ok(new { message = "ok", data = albumInfo2 })); } else { return(BadRequest(new { message = result })); } }
public ActionResult UploadImg2(UploadImgModel model) { var file = HttpContext.Request.Files[0]; if (file != null) { var path = Server.MapPath("~/upload/img"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var fileName = Path.Combine(path, DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + file.FileName); if (!fileName.ToLower().EndsWith(".jpg") && !fileName.ToLower().EndsWith(".jpeg")) { return(Content("<script>window.parent.alert('请上传jpg格式的图片')</script>")); } file.SaveAs(fileName); var _path = $"/upload/img/{Path.GetFileName(fileName)}"; return(Content($"<script>window.parent.$('#{model.FormId}').find('input[type=file]').val('');window.parent.$('#{model.ImgId}')[0].src = '{_path}';window.parent.$('#{model.ImgId}')[0].style.display='block'</script>")); } else { return(Content("<script>window.parent.alert('请选择上传图片')</script>")); } }
public HttpResponseMessage UploadImg(UploadImgModel model) { using (MobileStoreServiceEntities data = new MobileStoreServiceEntities()) { PRODUCT kq = data.PRODUCTs.FirstOrDefault(p => p.PRODUCT_ID == model.ID); kq.PRODUCT_IMG = model.Link; data.SaveChanges(); } return(CreateResponse(HttpStatusCode.OK)); }