Gabriel Gabriel - 1 year ago 389
reST (reStructuredText) Question

Spring rest with Spring Boot: Upload MultipartFile and Json object as parameters

I know this question was asked on stackoverflow before. However, I haven't found an answer that actually tests the service using, for example, Postman.

I have followed the documentation and my service is pretty much the same as described on the documentation:

public ResponseEntity<Void> uploadFile(@RequestPart(name="foo", required = false) Foo foo, @RequestPart("file") MultipartFile file) {
return new ResponseEntity<>(OK);

When I try to heat my service using Postman, I got the following error:

org.springframework.web.multipart.MultipartException: Current request is not a multipart request

And on postman, I got the following return


The question is: Is it possible to call my service using Postman? If it is, what parameters am I missing?

Answer Source

Yes it is possible to call your service using Postman.

Instead of sending JSON as text, create a file (e.g. test.json) containing JSON data that you want to send:

    "teste": "abc"

Then in form-data section change the type of your foo field from Text to File and choose JSON file that you've created.

And that's it. Click Send and your request should be processed without any error.

Note: Header should be left empty i.e. it should not contain any custom Content-Type value.