public async Task <IActionResult> UpdateVehiclesPicturePath([FromForm] VehiclePictureModel model) { try { if (ModelState.IsValid) { byte[] vehicleImage; using (var memoryStream = new MemoryStream()) { await model.VehicleImage.CopyToAsync(memoryStream); vehicleImage = memoryStream.ToArray(); } string guid = Guid.NewGuid().ToString(); string mime = model.VehicleImage.ContentType.Contains("/") ? model.VehicleImage.ContentType.Split("/")[1] : model.VehicleImage.ContentType; string fileName = $"{guid}.{mime}"; string realPath; try { realPath = _vehicleLogic.SaveVehiclesPicturePath(fileName, vehicleImage, model.VehicleId); } catch (Exception e) { return(StatusCode(500, e)); } if (string.IsNullOrWhiteSpace(realPath)) { return(BadRequest()); } return(Ok(realPath)); } else { return(BadRequest(ModelState)); } } catch (Exception e) { return(BadRequest(e)); } }