I currently have 2 APIs. One is in .NET Framework 4.6.2 and one is in .NET 8.
I'm trying to upload files and metadata as form-data though the .NET Framework API to the .NET 8 API. When uploading form-data through Postman or JavaScript directly to the .NET 8 API, it receives the files and stringified metadata perfectly fine. However, when trying to go through the .NET Framework API, no content ever shows up in the .NET 8 API.
Here is the endpoint for the .NET Framework API to read in the form data.
[HttpPost]
[Route("Route")]
public async Task<IHttpActionResult> UploadMultipleOrderForms() {
var provider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(provider);
List<Stream> files = new List<Stream>(); // I also tried this as byte[]
List<string> metadatas = new List<string>();
foreach (var part in provider.Contents) {
var name = part.Headers.ContentDisposition.Name.Trim('\"');
if (string.IsNullOrEmpty(part.Headers.ContentDisposition.FileName)) {
var fieldData = await part.ReadAsStringAsync();
metadatas.Add(fieldData);
}
else {
var fileData = await part.ReadAsStreamAsync();
files.Add(fileData);
}
}
return Ok(await UploadMultipleFiles(
files,
metadatas,
"azure-container",
Request.Headers.Authorization.Parameter
));
}
Here is the function that calls the .NET 8 API.
public async Task<IEnumerable<object>> UploadMultipleFiles(
IEnumerable<Stream> files,
IEnumerable<string> metadatas,
string containerName,
string jwt
) {
var client = new HttpClient();
client.BaseAddress = new Uri(_dotnet8ApiUrl);
var form = new MultipartFormDataContent();
foreach (var stream in files) {
var streamContent = new StreamContent(stream);
streamContent.Headers.ContentType = new MediaTypeHeaderValue("image/png");
form.Add(streamContent, "files", Guid.NewGuid().ToString());
}
foreach (var metadata in metadatas) {
form.Add(new StringContent(metadata), "metadatas");
}
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwt);
var response = await client.PostAsJsonAsync(
$"UploadEndpoint/{containerName}",
form
);
return new object[] { response };
}
Here is the function signature for the .NET 8 endpoint.
[HttpPost("UploadEndpoint/{containerName}")]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult> CreatBlobsAsync(
[FromForm] IEnumerable<IFormFile> files,
[FromForm] IEnumerable<string> metadatas,
[FromRoute] string containerName
) {
...
}
No matter what I try, both files and metadatas are null in the .NET 8 API when sending like this.

Any help is appreciated! Any other improvements that could be made are also appreciated.
Thanks!