public async Task <IActionResult> UploadFile(int projectId, int dirId) { try { var path = _fileService.GetFullPath(projectId); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (Request.ContentType.IndexOf("multipart/", StringComparison.OrdinalIgnoreCase) >= 0) { var file = Request.Form.Files[0]; if (file.Length <= 0) { return(BadRequest("File size is zero")); } using (var fileStream = new FileStream(Path.Combine(path, file.FileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } var fi = new FileInfo(Path.Combine(path, file.FileName)); _fileService.AddOrUpdateFile(projectId, fi, dirId); return(Ok()); } return(BadRequest($"Expected a multipart request, but got '{Request.ContentType}'")); } catch (Exception e) { return(BadRequest(e.Message)); } }