Reputation: 125
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
Upvotes: 1
Views: 494
Reputation: 975
Seems you need to add the following line in your http header request on the client side (where you are sending the rest request to your web-api).
Hope this helps.
Content-Type: application/json
Upvotes: 0