ASP Core WebApi Test File Upload using Postman

how to test web api using postman
file upload in web api using postman core api file upload
web api upload file with parameters web api file upload and multipart mime
how to upload a file and json data in postman c#
iformfile is null postman core web api multipart/form-data

I have created an endpoint that takes an arbitrary file:

public async Task<IActionResult> CreateFile(IFormFile file)

When I test it with Postman, the file is always null.

Here is what I am doing in Postman:

What am I doing wrong?

Thanks to @rmjoia's comment I got it working! Here is what I had to do in Postman:

How To Use Postman With ASP.NET Core Web API Testing, Testing PUT with Postman. First, we need to set HTTP Action from the dropdown list as PUT. Then, we need to type or paste into the API URL. UpdateTodo API accepts a Todo object in JSON format. To pass JSON data we need to Select Body Tab. Select the Raw format. Select JSON(Application/JSON) as text format. How To Use Postman With ASP.NET Core Web API Testing. If you are developer, tester, or a manager, sometimes understanding the various methods of API can be a challenge when building and consuming the application.

ASP.NET Core. Recipe #1. File(-s) upload/download with Postman , IMPORTANT: 'key' must match 'parameter name' in controller action /* Postman: Url: <host>/api/values/uploadfile. Verb: POST Body: form-data key (file): file For those of you who haven’t heard of Postman, and you’re a web developer, then I highly recommend that you take a look at it here. This tool is great for testing your API endpoints, especially in this cloud first / mobile first world. I recently wrote a File Upload controller methos in WebAPI and needed to test it quickly, so i fired up

Your should be like that

   public async Task<IActionResult> UploadFile([FromForm]UploadFile updateTenantRequest)

Your class should be like:-

public class UpdateTenantRequestdto

        public IFormFile TenantLogo { get; set; }

and then

Testing File Upload using Postman, I recently wrote a File Upload controller methos in WebAPI and needed to test it quickly, so i fired up Postman. Here's a basic controller method  Let’s see how to use POSTMAN to send an HTTP request to our local ASP.NET Web API Services and check the response. Step 1: Download and install POSTMAN from Postman. Step 2: Once the Postman is successfully installed, open the Postman.

   [HttpPost("UploadSingleFile"), Route("[action]")]
    public async Task<IActionResult> UploadSingleFile([FromForm(Name = "file")] IFormFile file)

        // Process uploaded files

        string folderName = "Uploads";
        string webRootPath = hostingEnvironment.WebRootPath;
        string newPath = Path.Combine(webRootPath, folderName);
        if (!Directory.Exists(newPath))

        Repository.Models.File fileModel = new Repository.Models.File();
        fileModel.Name = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
        fileModel.Path = $"{folderName}/{file.FileName}";
        fileModel.Size = file.Length;
        fileModel.Type = file.ContentType;

        string fullPath = Path.Combine(newPath, fileModel.Name);

        fileModel.Extension = Path.GetExtension(fullPath);
        fileModel.CreatedDate = Utility.Common.GetDate;
        fileModel.CreatedBy = 1;

        //fileModel save to db

        using (var stream = new FileStream(fullPath, FileMode.Create))
            await file.CopyToAsync(stream);

        return Ok(new { count = 1, path = filePath });

IFormFile parameter is null when uploading via Postman · Issue , I have to upload a file to a webapi service and struggled for many hours to get it going. The following is the controller code: // Handle the file  Test Web API in Postman. Click on the Send button to send an HTTP request to the provided URL. The response is displayed below. Response in Postman. As you can see above, HTTP response shows data and response status. Thus, you can use Postman to test your Web API. We will use Fiddler throughout this tutorial series.

.Net Core Web Api multipart/form-data, We're going to use Multipart/form-data approach for uploading files along with JSON Data. Net Core Web Api multipart/form-data – upload File with Form Data Choosing the right tool for writing API for your Client App is a crucial thing & no doubt that Dotnet Core considered as Testing with Postman. The record is inserted at 13th row. Step 4 Test PUT functionality. Hence, the data is updated in the database. Step 5 Finally, test Delete functionality. Conclusion Personally, I like using Postman to test Web API’s and WCF Services. We can also use Fiddler, but if API is too complex, I recommend using Fiddler,

File upload in ASP.NET Core web API, In this post, I will show how to upload a file in ASP.NET Core API and store it in Azure blob storage. To accept file Now, let's test with postman. File upload in ASP.NET Core web API. In this post, I will show how to upload a file in ASP.NET Core API and store it in Azure blob storage. To accept file type in action, you need to listen for IFormFile type object. Based on your requirement you can use IFormFile or ICollection<IFormFile> type as a parameter for API action.

Not able to post image to API controller in Postman : dotnet, [Route("upload")] [HttpPost] public async Task<IActionResult> I would like to test this out in Postman but I keep getting the error that the input https://docs.​ For anyone that is interested, I have this GitHub Repo for how I do unit testing in a Web Api project. The file name in Advanced Rest Client is fileUpload, but files[]/files in Postman. Can you change it to fileUpload in Postman as well? If not, you can select the 'binary' mode in Postman instead of 'form-data' and try uploading the file there.

  • have you tried with the form-data? and you should have a way to "simulate" a form too, by specifying the fields, and add the files too
  • And I also have the Header with the Content-Type = application/x-www-form-urlencoded
  • I got it working with form-data. I didn't need to add the content-type header.
  • I also wondering to transfer file but it helped me thanks. @Zeus82 can you explain or refer any link how to transfer file when I have other JSON parameters in request.
  • This is good. I am able to upload single file. However your example for multiple files, I continue to get the error in postman (following). Have you seen this? { "": [ "The input was not valid." ] }
  • In order to send multiple files I had to change my method signature to ... public async Task<IActionResult> UploadFiles(IFormFileCollection files) using List<IFormFile> files as upload multiple did not work for me.
  • For sending multiple files, both IFomFileCollection and List<IFormFile> should work. You should check you parameter name and Model validation, if you couldn't understand problem. monitor you request, because sometimes the request is not the same you are expecting.
  • +1 for David. I needed to use IFormFileCollection too. Using List didn't work for me also. I'm curious about it, List should work too I guess.
  • Just a comment to note that with this Postman file upload method, make sure to match the "Key" name in the form-data with the method input parameter name otherwise the file just shows up as null. For example: if the method is UploadFile(IFormFile myFile) make sure that in Postman you set the key field as "myFile".
  • Welcome to Stack Overflow! Please don't answer just with source code. Try to provide a nice description about how your solution works. See: How do I write a good answer?. Thanks