public async Task <IActionResult> Upload(string targetId, string feedType, string contentType, string dateCreated, string description, [FromForm] List <IFormFile> files) { var userId = _identityHelper.GetObjectId(User.Identity as ClaimsIdentity); var targetIdGuid = Guid.Parse(targetId); var timeStamp = (string)dateCreated; if (targetId == null || string.IsNullOrWhiteSpace(feedType) || string.IsNullOrWhiteSpace(contentType) || string.IsNullOrWhiteSpace(timeStamp) ) { return(BadRequest()); } var user = _userRepository.GetByObjectId(userId); if (user == null) { return(Unauthorized()); } var postedFile = Request.Form.Files.FirstOrDefault(); if (postedFile == null) { return(BadRequest()); } var queryInfo = Request.Form; FeedItem fileInfo = new FeedItem(FeedItem.ImageFeedItem) { Id = Guid.NewGuid(), // todo: This will throw exception for bad timestamps. Add code to validate this DateCreated = DateTime.Parse(timeStamp), }; switch (feedType) { case FeedGroup.BoardFeedType: var board = _boardsRepository.GetById(targetIdGuid); if (board == null) { return(NotFound()); } fileInfo.Title = postedFile.Name; await _contentUploadService .UploadFile(fileInfo, user, postedFile.ContentType, postedFile.OpenReadStream(), feedType, board, description); break; case FeedGroup.UserFeedType: fileInfo.Title = postedFile.Name; try { await _contentUploadService.UploadFile(fileInfo, user, postedFile.ContentType, postedFile.OpenReadStream(), feedType, description); break; } catch (Exception e) { return(StatusCode(Status500InternalServerError)); } default: return(BadRequest()); } return(StatusCode(Status201Created)); }