I'm making a Web API and I need to post data to another API controller.
The API method POST of the controller looks like this:
public async Task<IActionResult>
ImportFile([FromForm] ImportData data)
{
var result = await _service.ImportData(data);
return Ok(result);
}
The ImportData looks like this:
public class ImportData
{
[Required]
public IFormFile File {get;set;}
[Required]
public string name{get;set;}
}
I have the same DTO to consume the endpoint of the controller, but for the IFormFile I only have available a encoded64 string, so in my DTO I substitute IFormFile for byte[].
How do I generate the IFormFile with the string to feed the DTO and make the request?
How do I populate the form of the request?(because the controller has [FromForm]
My current request:
ImportDataDTO data = new ImportDataDTO ();
data.file = Convert.FromBase64String(encodeStringFile);
data.name = "my name";
await httpclient.PostAsync(URL, data);
Regards