Q:

Attach base64 string converted image to request form data in backend?

so I have a base64 string that will be passed into an endpoint in which I need to convert it to an image then attach it in the form-data. Is that possible?
Right now I have something like this 
Image img = options.base64String.ToImage();

And I want the image to be attached in the request's form data so I could get it like this:
Image img = options.base64String.ToImage();

Request.Form.Files.Add(img); // I want to add the image on something like this

var files = Request.Form.Files;

I want to attach the img to the Request.Form.Files
Also note that I only have access to the API of the app.
Thanks!

A:

The HttpRequest object cannot be modified; it's immutable throughout the duration of the request. This includes the HttpRequest.Form.Files.
You can affect the way the request input stream data is processed. Since the input stream includes the Form fields, it might be possible to use filters to modify the form data on the request. However, it does have caveats:

This only works very early on in the request pipeline. As soon as anything in the pipeline interacts with the input stream (including e.g. reading anything from Form), you're too late.
You're working with the raw data stream. No Form["Hello"] is going to work here - you need to look at how HTTP forms are encoded, parse the data precisely, and recreate the correct changed form data on the fly.

Unless you really have no other option, I'd recommend avoiding that.
A relatively simple alternative would be creating a new web request using the actual request data, and returning the result from that (make sure the request you make doesn't cause another request, or you might end up with an infinite loop blocking your service :)). You'll need to make sure the new request you're making has all the right data, of course; there's no simple way to turn HttpRequest into a new HttpWebRequest.

