Skip to content
Loading
How to create ASP .NET Web API Using form-data in Postman.  
  •   
  •  
    API is 
    1. public class UploadController : ApiController  
    2. {  
    3.     public async Task PostFormData()  
    4.     {  
    5.         // Check if the request contains multipart/form-data.  
    6.         if (!Request.Content.IsMimeMultipartContent())  
    7.         {  
    8.             throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);  
    9.         }  
    10.   
    11.         string root = HttpContext.Current.Server.MapPath("~/App_Data");  
    12.         var provider = new MultipartFormDataStreamProvider(root);  
    13.   
    14.         try  
    15.         {  
    16.             // Read the form data.  
    17.             await Request.Content.ReadAsMultipartAsync(provider);  
    18.   
    19.             // This illustrates how to get the file names.  
    20.             foreach (MultipartFileData file in provider.FileData)  
    21.             {  
    22.                 Trace.WriteLine(file.Headers.ContentDisposition.FileName);  
    23.                 Trace.WriteLine("Server file path: " + file.LocalFileName);  
    24.             }  
    25.             return Request.CreateResponse(HttpStatusCode.OK);  
    26.         }  
    27.         catch (System.Exception e)  
    28.         {  
    29.             return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);  
    30.         }  
    31.     }  
    32.   
    33. }  
     you can now use Postman instead of Html. API will be same.
    +1
  • Srinivasan Ramamoorthi
    check this link
    https://www.c-sharpcorner.com/UploadFile/0c1bb2/inserting-Asp-Net-form-data-into-database-using-web-api/ 
    +1
  • Giri Sain
    i want in asp.net c#
    +1
  • Srinivasan Ramamoorthi
    Please check this article
     
     https://stackoverflow.com/questions/51683792/how-to-get-form-data-from-postman-to-webapi
    +1
  • Ketan Mokariya
    You can create a web API to handle multipart form data and process files like images, text, etc. 
     
    Have a look at following article
    https://codingcanvas.com/different-ways-of-uploading-files-using-http-based-apis-part-1/
    +1