Jacek Kaczmarek
Jacek Kaczmarek

Reputation: 103

How to send file and object using postman?

I have an endpoint which is adding files and object. Here are the function parameters:

@RequestMapping(
    value = "/request",
    method = RequestMethod.POST,
    consumes = {"multipart/form-data"}
)
@ResponseBody
@Transactional
public ResponseEntity<Object> requestLicense(
    @RequestPart("properties") @Valid LicenseRequest request,
    @RequestPart("file1") @Valid @NotNull @NotBlank MultipartFile file1,
    @RequestPart("file2") @Valid @NotNull @NotBlank MultipartFile file2
) {
    ...
}

And I would like to send correct post method using postman but I do not know how to do it.

How do I do it or it is impossible?

Upvotes: 0

Views: 618

Answers (2)

Majid Roustaei
Majid Roustaei

Reputation: 1764

yes it is possible and you have done lots of it yourself.

just remind that you have two files in your endpoint's requirements and they both are annotated with @NotNull, so you need to send two files with the specified names (which are file1 and file2 in your case).

these names should exactly be in the key part of your form-data.

have a look on this:

enter image description here

Upvotes: 1

simonarame
simonarame

Reputation: 375

So as mentioned by Majid_Roustaei answer, a valid post to the method needs to contain 2 separate files parameters, namely file1 and file2 plus the properties parameter.

It is the purpose of the Multipart Form-Data.:

enter image description here

You are almost there !

Upvotes: 1

Related Questions