2

I have a client that uploads a file to an API (see code):

using (var client = new HttpClient())
{
   using (var content = new MultipartFormDataContent())
   {
      // THIS LINE SHOULD BE CHANGED TO RETURN A Base64 StreamContent object 
      var fileContent = new StreamContent(File.OpenRead(txtFileLocation.Text));

      fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
              FileName = Path.GetFileName(@"C:\text.mp4")

      content.Add(fileContent);

      var result = client.PostAsync("http://localhost:1234/api/upload", content).Result;
    }
}

The API expects a MIME base64 file.

I'm familiar with how to encode a file into a string base64. What I don't know is: how can I pass this string as a MIME File Upload to the API?

Rosa
  • 632
  • 6
  • 20
SF Developer
  • 4,996
  • 14
  • 55
  • 100
  • 1
    http://stackoverflow.com/questions/19134062/encode-a-filestream-to-base64-with-c-sharp – Joel Allison May 10 '14 at 00:35
  • Yes I'm familiar with encoding a file, what I don't know is how to then pass it to the API File Upload so that it still arrives as MIME and can be decoded on the server. – SF Developer May 10 '14 at 15:09

0 Answers0