public async Task <IActionResult> UploadImage([FromForm] CharacterFileInputModel file) { var foundCharacter = await _characterService.Get(file.CharacterId); // Needs to be a game that can use image if (foundCharacter == null) { return(BadRequest()); // Dont add a image that would not be used } foundCharacter.Images.Add(_characterService.CreateImageFile(file)); await _characterService.Update(foundCharacter.CharacterId, foundCharacter); return(CreatedAtRoute("GetCharacterImage", new { CharacterId = file.CharacterId }, foundCharacter)); }
public string CreateImageFile(CharacterFileInputModel file) { string wwwrootPath = _hosting.WebRootPath; string gameFolderPath = Path.Combine(wwwrootPath, "images", "characters", file.CharacterId); if (!Directory.Exists(gameFolderPath)) { Directory.CreateDirectory(gameFolderPath); } string absolutePath = Path.Combine(gameFolderPath, file.File.FileName); using (var fileStream = new FileStream(absolutePath, FileMode.Create)){ file.File.CopyTo(fileStream); } return(Path.Combine("images", "characters", file.CharacterId, file.File.FileName)); }