Multipartexception: Current Request Is Not a Multipart Request

MultipartException: Current request is not a multipart request

When you are using Postman for multipart request then don't specify a custom Content-Type in Header. So your Header tab in Postman should be empty. Postman will determine form-data boundary. In Body tab of Postman you should select form-data and select file type. You can find related discussion at https://github.com/postmanlabs/postman-app-support/issues/576

Current request is not a multipart request with Postman

Try using Body as "form-data" in Postman. Then in the "KEY" column select file instead of text, set the key as file and select the file to upload. Additionally, make sure that in the Headers tab you don't have any manually added Content-Type. Postman will derive it based on Body tab.

Check here a Postman example

What causes "Current request is not a multipart request" and how do I fix it?

when try hit from any rest client don't set any content type in header(your header should be empty )

or you can have html file with below code in action specify your api url

<form action="your_api_url" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
</form>

Although I wrote 'enctype="multipart/form-data', ERROR 'Current request is not a multipart request' happen

Try adding content-type: multipart/form-data in header of your axios call.

headers: {
'x-access-token': `${localStorage.getItem('token')}`,
'content-type': 'multipart/form-data'
}

Also your axios post data should be in FormData type

var dataBody = new FormData();
dataBody .append('content', this.content);
dataBody .append('files', this.files);

change params to data and set it to dataBody

axios({
url:'http://127.0.0.1:8080/article',
method:'post',
headers: {
'x-access-token': `${localStorage.getItem('token')}`,
'content-type': 'multipart/form-data'
},
data: dataBody
}

Finally, at your backend:
Add consumes = { MediaType.MULTIPART_FORM_DATA_VALUE } in @PostMapping.
Replace @RequestParams with @RequestPart.

@PostMapping("/article", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
@ApiOperation(value = "게시글 작성")
public Object postArticle(@RequestPart String content, @RequestPart(required = true) List<MultipartFile> files)


Related Topics



Leave a reply



Submit