private string UploadedFile(VerifierRequest model) { var file = Request.Form.Files[0]; var folderName = Path.Combine("Resource", "images"); var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName); string dbPath = null; if (file.Length > 0) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var fullPath = Path.Combine(pathToSave, fileName); dbPath = Path.Combine(folderName, fileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); } } return(dbPath); }
public ActionResult Create([FromForm] VerifierRequest verifierRequest) { try { string uniqueFileName = UploadedFile(verifierRequest); Verifier verifier = new Verifier { Status = "Unverified", LinkImage = uniqueFileName }; _context.Add(verifier); _context.SaveChanges(); return(StatusCode(201, new { message = "UpLoad Success" })); } catch (Exception ex) { return(StatusCode(500, new { message = ex.Message })); } }