public async Task <AjaxResponse> Upload() { if (!Request.Content.IsMimeMultipartContent("form-data")) { return(new AjaxResponse(new ErrorInfo("无效请求"))); } HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; HttpRequestBase request = context.Request; var files = request.Files; string rootPath = HttpContext.Current.Server.MapPath("/"); // var provider = new MultipartFormDataStreamProvider(rootPath); // await Request.Content.ReadAsMultipartAsync(provider); // var file = provider.FileData[0]; // var fileInfo = new FileInfo(file.LocalFileName); // var image = Image.FromStream(fileInfo.OpenRead()); ImgUploadHelper uploadHelper = new ImgUploadHelper(request.Files, rootPath); var result = uploadHelper.UploadImg(); //string msg = result.Item1 == ImageUploadStatus.Success ? result.Item2 : result.Item2; return(new AjaxResponse(new { success = result.Item1 == ImageUploadStatus.Success, msg = result.Item2 })); //return Json(new { success = result.Item1 == ImageUploadStatus.Success, msg = msg }); }
public ActionResult MainToUploadImg() { HttpPostedFileBase file = Request.Files["file"]; string msg = string.Empty, filePath = "/Content/GameImg/"; msg = ImgUploadHelper.CommonUploadImg(file, out msg, filePath); return(Content(msg)); }
public JsonResult Upload() { ImgUploadHelper uploadHelper = new ImgUploadHelper(Request.Files, Server.MapPath("/")); var result = uploadHelper.UploadImg(); //string msg = result.Item1 == ImageUploadStatus.Success ? (uploadHelper.FileServer + result.Item2) : result.Item2; return(Json(new { success = result.Item1 == ImageUploadStatus.Success, msg = result.Item2 })); }
public HomeController(ApplicationDbContext db, IHostingEnvironment environment, IFileManager manager, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager) { _db = db; hosting = environment; _imgHelper = new ImgUploadHelper(hosting, manager); _userManagementHelper = new UserManagementHelper(_db); _userManager = userManager; _roleManager = roleManager; }
public ProfilController(ApplicationDbContext db, IHostingEnvironment environment, IFileManager manager, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager, SignInManager <ApplicationUser> signInManager, UrlEncoder urlEncoder, ILogger <AccountController> logger) { _db = db; hosting = environment; _imgHelper = new ImgUploadHelper(hosting, manager); _userManagementHelper = new UserManagementHelper(_db); _userManager = userManager; _roleManager = roleManager; _userManager = userManager; _signInManager = signInManager; _roleManager = roleManager; _urlEncoder = urlEncoder; _logger = logger; }