public async Task <IActionResult> OnPostUpload([FromQuery] IFormFile img) { FileStorage _storage = new FileStorage(); var extension = System.IO.Path.GetExtension(img.FileName); // check for a valid mediatype if (!img.ContentType.StartsWith("image/")) { return(new JsonResult(new UIResult() { Data = null, Status = 0, Text = "فارمت عکس درست نیست", // Can be changed from app settings Description = "" })); } else { //var image = Image.FromStream(img.OpenReadStream(), true, true); string filename = await _storage.CreateAsync(img.OpenReadStream(), extension, _configuration["Photo"]); var result = new { status = "success", url = filename }; return(new JsonResult(result)); } }
public async Task <IActionResult> OnPostUpload([FromForm] IFormFile attachement) { if (attachement.ContentType.StartsWith("image/") || attachement.ContentType.Contains("pdf")) { FileStorage _storage = new FileStorage(); var extension = System.IO.Path.GetExtension(attachement.FileName); string filename = await _storage.CreateAsync(attachement.OpenReadStream(), extension, _configuration["Document"]); var result = new { Status = 1, Text = "فایل موفقانه ارسال گردید", Description = "لطفاً فورم را درج نموده و ارسال بدارید", url = filename }; return(new JsonResult(result)); } else { var result = new { Status = 0, Text = "فارمت فایل درست نیست", Description = "لطفاً فایل تان را به عکس یا به PDF تبدیل نموده ضمیمه بسازید." }; return(new JsonResult(result)); } }