I have found several tutorials on how to upload an image or multiple images in Xamarin. However, I have not found how to send multiple images with each image containing some satellite data.
This is how the model looks like on the server:
public class AppFileDTO
{
public IFormFile File { get; set; }
public string CategoryName { get; set; }
public string CategoryDescription { get; set; }
public string Detail { get; set; }
}
But the controller needs a list of data. Here is the Asp.Net Web Api endpoint:
[HttpPost("UploadAppFiles/{id}")]
public async Task<IActionResult> UploadAppFiles(int id, IEnumerable<AppFileDTO> appFileDTOs)
{
...
}
How can I upload something like that?
I found something on stack overflow on how to upload a single image with satellite data:
MultipartFormDataContent multiContent = new MultipartFormDataContent();
// Image 1
HttpContent fileStreamContent = new StreamContent(vm[0].File);
fileStreamContent.Headers.ContentDisposition = new
System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
{
Name = "File",
FileName = vm[0].File.FileName
};
fileStreamContent.Headers.ContentType = new
System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
multiContent.Add(fileStreamContent );
// Satellite data, image 1
multiContent.Add(new StringContent(vm[0].CategoryName), "CategoryName");
multiContent.Add(new StringContent(vm[0].CategoryDescription), "CategoryDescription");
multiContent.Add(new StringContent(vm[0].Detail), "Detail");
// Send
var response = await client.PostAsync(url, multiContent);
How would you upload multiple?
This is how I upload the images on Postman for testing purposes, which works perfectly: