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.
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
Remove Duplicates from a List of Objects Based on Property in Java 8
Printing a Statement Only Once in a While Loop
Spring Junit: How to Mock Autowired Component in Autowired Component
How to Get Http Response Code Using Selenium Webdriver
Java.Sql.Sqlexception: Access Denied for User 'Root'@'Localhost' (Using Password: Yes)
How to Fix Expected Begin_Object But Was String in Retrofit
Java - How to Find Students With Their Highest Marks Writing a Method in a Student Class
How to Tell a Mockito Mock Object to Return Something Different the Next Time It Is Called
Java Package Does Not Exist Error
Calculating the Sum of Number and Its Reverse in Java
Java How to Retrieve More Than 1 Million Rows in a Resultset
How to Create Unique Column With Jpa
Sqlite_Error - SQL Error or Missing Database (Near "Autoincrement": Syntax Error)
Regex to Match Substring After Nth Occurence of Pipe Character
Hibernate Error Executing Ddl Via Jdbc Statement
Get Current Week Start and End Date in Java - (Monday to Sunday)