public async Task <IActionResult> UploadFile(string reportId, string incidentId, IFormFile file) { if (!Directory.Exists(_uploadsPath)) { Directory.CreateDirectory(_uploadsPath); } var report = _storageFacade.GetReport(reportId); var incident = report?.Incidents.FirstOrDefault(i => i.Id == incidentId); if (incident == null) { return(NotFound("There is no such report or incident.")); } if (file == null) { return(NotFound("File can't be null")); } var list = new List <string>(incident.Attachments); var fileName = Guid.NewGuid() + Path.GetExtension(file.FileName); var fullPath = Path.Combine(_uploadsPath, fileName); using (var fileStream = new FileStream(fullPath, FileMode.Create)) { await file.CopyToAsync(fileStream); } list.Add(fileName); incident.Attachments = list.ToArray(); _storageFacade.UpdateReport(report); byte[] fileBytes = System.IO.File.ReadAllBytes(fullPath); return(Ok("data:image/png;base64," + Convert.ToBase64String(fileBytes))); }
public IActionResult UpdateReport([FromBody] Report report) { Debug.WriteLine("CreateReport"); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var id = _storageFacade.UpdateReport(report); return(Ok(id)); }