Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to send an image and additional data in ASP.NET WebAPI with Postman?

I am trying to send an image and additional data, for example, userId to my API. But, these are two different types.

How to send an image and some additional data in Postman?

like image 869
Hamed Hajiloo Avatar asked Aug 02 '19 07:08

Hamed Hajiloo


People also ask

How do I send data from postman to Web API?

From Postman tool - right pane select GET from DropDown, then enter your Web API url like http://localhost:<portnumber>/api/supplier and click on Send button. This will make a request to Web API server and get response. You can get response in JSON, XML, HTML, Text format.


2 Answers

For small files (eg up to 200 to 300 MB) you can use the following 2 tutorials to tell you the trick.

1 | 2

But if your file is too large (eg 500 megabytes up to several gigabytes) Better use the Chunk method (crushing the bulk file into smaller pieces and then uploading these pieces and eventually stacking them to the server)

The following table has implemented this feature well To do this, you need to write both the server-side of the code and the client-side of the plugin to do the chunking work (albeit handy but easier with the plugin) such as this Resumable.js plugin

Note: Be sure to run the program on Kestrel to run it, otherwise it has restrictions in IISExpress mode.


refrence : DotNetZoom Channle in Telegram

like image 130
Hamed Hajiloo Avatar answered Nov 02 '22 14:11

Hamed Hajiloo


First, create an action which receives IFormData and a string caption ( you can put them in a separate class if you want ) :

[Route("api/[controller]")]
public class PostsController : ControllerBase
{
    [HttpPost]
    public async Task<IActionResult> Create(IFormFile image, string caption)
    {
        // Save image here
        return Ok(caption);
    }
}

and with Postman, simply submit a form-data request like this :

enter image description here

like image 40
Moien Tajik Avatar answered Nov 02 '22 14:11

Moien Tajik