-1

I'm wondering how to post files in the request body to an API controller in .NET framework using react. I need to do this without altering the request headers, meaning I need to send it as application/json.

What I need is something like this:

public IHttpActionResult SaveFiles([FromBody] Files[] files)

I've tried this approach, without success:

let formData = new FormData();
    images.forEach((image, i) => {
      formData.append(i, image);
    });

    post('/api/returns/savefiles', formData)
    .then(response => {...

Any help is much appreciated.

BigMac
  • 29
  • 1
  • 7
  • Do you have control of the API? It's hard to know what the request should look like without knowing how the server would handle it. I guess that an option is base64 encoding all your images and sending an array of base64 strings in the request body. – ijmorales Dec 31 '20 at 14:07

1 Answers1

0

I think this isn't the best approach but you can encode your images into base64 strings and decode them on the API's side.

If my answer wasn't helpful, try taking a look at this question: How do I upload a file with metadata using a REST web service?

Hairy Cat
  • 51
  • 5