none
c# 400 Bad request when trying to pass files through Rest API RRS feed

  • Question

  • Hi all i have been trying to post files for a third party tool through rest api with MultipartFormDataContent. Even though i am writing files to MultipartFordatacontent in byte arry i am receiving error saying "400 bad request no filedata section found in multipart post request".

    Request:

    Method: POST, RequestUri: 'url', Version: 1.1, Content: System.Net.Http.MultipartFormDataContent, Headers:
    {
      
      Content-Type: multipart/form-data; boundary="4c10d3d0-f2ac-467e-9b46-3ca172eb646d"
      Content-Length: 185
    }
    --c4757eb4-aefd-450a-a5cc-e879ac7f37ce
    Content-Dis-data; name=filedata; filename=pp.txt
    Content-Type: text/plain

    test file
    --c4757eb4-aefd-450a-a5cc-e879ac7f37ce--


    Response:
    StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
    {
      x-transaction-id: 99999_staging_1537571080:f4e44b3ca701:28:jm91oq79:10113
      vary: accept-encoding
      Connection: keep-alive
      Cache-Control: no-cache
      Date: Fri, 21 Sep 2018 23:04:08 GMT
      Content-Length: 104
      Content-Type: application/json; charset=utf-8
    }
    {"statusCode":400,"error":"Bad Request","message":"No filedata section found in multipart POST request"}
    Friday, September 21, 2018 11:09 PM

All replies

  • It's probably where you need to post.

    https://forums.asp.net/28.aspx/1?WCF+ASMX+and+other+Web+Services

    Saturday, September 22, 2018 9:11 AM
  • Hi Post file through Rest Api returnin Bad request,

    Thank you for posting here.

    For your question, what is the type of your project? Desktop application or ASP.net application?

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 24, 2018 2:43 AM
    Moderator
  • Hi Wendy its a simple console application.
    Monday, September 24, 2018 8:54 AM
  • Please post the code you're using. The error seems to be coming from the remote server and seems to indicate they are expecting a file as part of the data and aren't getting it. Can you make this call successfully using Postman? If not then you'll probably want to get that working first. Then you can replicate it in your C# code.

    Michael Taylor http://www.michaeltaylorp3.net

    Monday, September 24, 2018 2:10 PM
    Moderator