Current request is not a multipart request Spring boot error while trying to upload a Image file.
Spring Boot
@PostMapping(value = "/add-item")
public ResponseEntity<?> handleProductInsert ( @RequestParam MultipartFile thumbnailFile ){
try{
.....................
.....................
return new ResponseEntity("Product added successfully", HttpStatus.OK);
}catch (Exception e){
return new ResponseEntity("Internal Server Error. Try again later",
HttpStatus.INTERNAL_SERVER_ERROR);
}
}
React App
state={data:null}
handleChange=(e)=>{
this.setState({data:e.target.files[0]});
}
connectToDatabase=async()=>{
return await axios.post(`https://localhost:8080/add-item`, this.state.data);
}
render()=>{
return (<>
<input accept="image/*" onChange={this.handleChange} type="file" />
<button onClick={this.connectToDatabase}>Submit</button>
</>
)
}