Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am trying to read response after uploading an attachment using web API c#. Getting below error:

no mediaTypeFormatter is available to read an object of type 'String' from content with media type 'multipart/form-data.

Here is my part of code:

string filepath = "C:/Users/O42895/Desktop/DownloadAttachmen20189t.jpg";
              string filename = "DownloadAttachmen20189t.jpg";

              MultipartFormDataContent content = new MultipartFormDataContent();
              ByteArrayContent fileContent = new ByteArrayContent(System.IO.File.ReadAllBytes(filepath));
              fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = filename };
              content.Add(fileContent);
                
              client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("multipart/form-data"));

              response = await client.PostAsync("https:--.com/flex/upload/document/genericattachment", content);

var resBody = response.Content.ReadAsStringAsync().Result;
                  Console.WriteLine(resBody);

I am getting the response but unable to print or read. Please let me know if any one knows


What I have tried:

Tried all possible ways but didnt help
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900