I need to post data another API. That API build with DotNet Core.
Model that I have data and same model I need to post another API.
public class SaveViewModel
{
public string Description { get; set; }
public List<SaveAttachment> Attachments { get; set; }
}
public class SaveAttachment
{
public string AttachCode { get; set; }
public IFormFile File { get; set; }
}
I try as below but that way I only sent list of file but I need to send List<SaveAttachment>
.
MultipartFormDataContent multiContent = new MultipartFormDataContent();
multiContent.Add(new StringContent(model.Description), "Description");
if (model.Attachments != null)
{
foreach (var item in model.Attachments)
{
multiContent.Add(new StreamContent(item.File.OpenReadStream())
{
Headers = { ContentLength = item.File.Length, ContentType = new MediaTypeHeaderValue(item.File.ContentType) }
}, "Attachments", item.File.FileName);
}
}