Invalid 'HttpContent' instance provided. It does not have a 'multipart' content-type header with a 'boundary' parameter

前端 未结 2 1505
栀梦
栀梦 2021-01-17 09:34

I\'m writing a web api that have a post method accepting files from uploaded from UI.

public async Task> PostAsync()
    {

                 


        
相关标签:
2条回答
  • 2021-01-17 10:01

    First: Postman have a bug in handling file-based requests.

    You can try adding this to your WebApiConfig.cs it worked for me:

    GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
    
    0 讨论(0)
  • 2021-01-17 10:20

    You are looking on the response header which is json format and this is ok for you.

    Your real problem is with the postman request, so just remove the 'Content-Type: multipart/form-data' entry from request header. It's enough to upload a file as form-data and send the request.

    Look what happen when you set the Content-Type manually vs. when you not:

    Postman knows to set both the content type and boundary, since you set only the content type

    0 讨论(0)
提交回复
热议问题