0

First time posting! I've been breaking my head on this particular case. I've got a Web application that needs to upload a file towards a web-api and receive an SVG file (in a string) back.

The web-app uploads the file as follows:

using (var client = new WebClient())
            {
                var response = client.UploadFile(apiUrl, FileIGotEarlierInMyCode);

                ViewBag.MessageTest = response.ToString();
            }

Above works, but then we get to the API Part: How do I access the uploaded file? Pseudocode:

public string Post([FromBody]File f)
        {
            File uploadedFile = f;

            String svgString = ConvertDataToSVG(uploadedFile);
            return s;
        }

In other words: How do I upload/send an XML-file to my Web-api, use/manipulate it there and send other data back?

Thanks in advance! Nick

PS: I tried this answer: Accessing the exact data sent using WebClient.UploadData on the server But my code did not compile on Request.InputStream.

Community
  • 1
  • 1

1 Answers1

0

The reason Request.InputStream didn't work for you is that the Request property can refer to different types of Request objects, depending on what kind of ASP.NET solution you are developing. There is:

You are using Web API, so HttpRequestMessage it is. Here is how you read the raw request bytes using this class:

var data = Request.Content.ReadAsByteArrayAsync().Result;
Paul-Jan
  • 16,746
  • 1
  • 63
  • 95