public async Task <IActionResult> FileUpload(List <IFormFile> files, long userId, int sourceType, int lang = 1) { //long userId = 0; //int lang = 1; long size = files.Sum(f => f.Length); //var filePaths = new List<string>(); IList <FileType> managedFiles = new List <FileType>(); foreach (var formFile in files) { if (formFile.Length > 0) { // full path to file in temp location var filePath = Path.GetTempFileName(); //we are using Temp file name just for the example. Add your own file path. //filePaths.Add(filePath); using (var stream = new FileStream(filePath, FileMode.Create)) { await formFile.CopyToAsync(stream).ContinueWith(t => { if (t.IsCompletedSuccessfully) { managedFiles.Add(new FileType { UserId = userId, Name = formFile.FileName, Path = filePath, Size = formFile.Length, SourceType = (FileSourceType)sourceType, Type = formFile.ContentType }); } }); } } } FileDB.AddFiles(managedFiles, sourceType, userId, lang, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION)); //ViewBag.Message = "Files uploaded"; // process uploaded files // Don't rely on or trust the FileName property without validation. return(Ok(new { count = files.Count, size, managedFiles })); }