Can any one support me, i am doing the simple stuff that is i am try to save image into database that is uploaded by postman i am using STS with spring boot and jpa database is H2. i tried get/put/post/delete from postman on plain text its working fine and also working fine when GET the image in postman. i have issues in posting image
model class code
@Entity
public class Alian
{
@Id
private int aid;
private String aname;
@Lob
private byte[] pic;
controller class code is. repo is dao class object.
@ResponseBody
@RequestMapping(path="/alian", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE )
public Alian Saving(@RequestBody Alian alian, @RequestParam("file") MultipartFile file)
{
repo.save(alian);
return alian;
}
error at postman is.
{
"timestamp": "2018-08-13T19:18:47.246+0000",
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'multipart/form-data;boundary=--------------------------175574471409780768513459;charset=UTF-8' not supported",
"path": "/alian"
}
You can't send @RequestBody along with MultipartFile and you don't even need it in your case. Send only MultiPartFile.
public Alian Saving(@RequestParam("file") MultipartFile file) {
Alian alian = new Alian();
alian.setPic(file.getBytes());
alian.setAname(file.getOriginalFilename());
return repo.save(alian);
}
You can use multipart/form-data
.
See https://www.getpostman.com/docs/v6/postman/sending_api_requests/requests#form-data
Ensure that you are not adding content-type manually.
There is no need to add a content-type header manually. You are overriding the value set by Postman. Just select form-data in POST request and send your request to see if it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.