List<IFormFile>
заменил на List<Image>
. Пытаюсь делать вот так foreach (var image in images)
{
using (var ms = new MemoryStream())
{
image.CopyTo(ms);
var fileBytes = ms.ToArray();
string base64Content = Convert.ToBase64String(fileBytes);
feedBack.Images.Add(new Image(image.FileName.Replace(" ", "_").Replace(".", "_").ToString(), base64Content));
}
}
но происходит ошибка Object reference not set to an instance of an object
public async Task<ActionResult> View(FeedBack feedBack, List<IFormFile> images)
{
if (ModelState.IsValid)
{
if (images.Count() > 0)
{
feedBack.Images = images.ToList();
}
var editResult = await _feedBackProvider.EditFeedBackAsync(feedBack);
if (editResult.HasError)
{
throw new Exception(editResult.Message);
}
var feedBackId = editResult.ResponseObject;
if (feedBack.NpsId != 0)
{
await _npsProvider.LinkFeedBackAsync(feedBack.NpsId, feedBackId);
return RedirectToAction("Index", "Nps");
}
return RedirectToAction("Index", "FeedBack");
}
var feedBackViewModel = await GetFeedBackViewModel(feedBack);
return View(feedBackViewModel);
}
public async Task<T?> SendHttpPutRequest<T>(string url, object data = null) where T : new()
{
try
{
var httpClient = _httpClientFactory.CreateClient();
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", await GetTokenAsync());
using HttpContent httpContent = new ObjectContent(typeof(object), data,
new JsonMediaTypeFormatter());
var response = await httpClient.PutAsync($"{AppSettings.WebApiVega}{url}", httpContent);
var responseBody = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
throw new Exception(responseBody);
}
response.EnsureSuccessStatusCode();
return JsonConvert.DeserializeObject<T>(responseBody);
}
catch (Exception exception)
{
Logger.LogError(exception, $"Ошибка при выполнении Update запроса {url}. {data}");
throw new Exception(exception.Message);
}
}
List<IFormFile>