mardi 1 décembre 2020

Store locally a binary file file received as HTTP POST body in C# Web ASP.NET

my problem might look simple for most of you. I need to save locally a file that i receive as an HTTP POST binary file. I also need to read some values from the HTTP header, but i think i can find a way to do this (i would love if the answer covered this part too).

I am working with a clean C# Web ASP.NET project. Here is a sample of the "look" of the code that i expect to reach in the API callback:

public class ValuesController : ApiController
{
    // POST api/values
    public string Post( /* do i need this?-> [FromBody] SomeModel value */)
    {
        /*
            -- I read some key:value pairs from the header --
            
            var val_1 = HeadersHere.getSpecificKey("name1");   
            var val_1 = HeadersHere.getSpecificKey("name2");   
            var val_1 = HeadersHere.getSpecificKey("name3");   

            -- But i need to also store locally a binary file sent in the http body --
            
            Stream s = SomeCodeHere.body.toStreamSomeHow();

            MyRoutineThatStoresTheFile("filename.dat", s);
        */


        return "Some Ok code";
    }
}



Aucun commentaire:

Enregistrer un commentaire