File(resume) upload using spring-mvc
I am uploading a file (a Microsoft office word document) using spring mvc.
For that I am using springorg.springframework.web.multipart.MultipartFile
.
I'm able to upload the file but facing problems in storing it in a MySQL database.
When I save the file as multipartFile obtained from the form submission (MultipartFile multipartFile = employee.getFile();
). It's saved in the database as object named as
org.springframework.web.multipart.commons.CommonsMultipartFile@1c79dfc.
I want to store the data as string (present in the file). How do I convert multipartFile in string format such that I can save it in a MySQL database using type TEXT.
Here's the info on multipartFile:
MultipartFile multipartFile = employee.getFile();
byte[] content=multipartFile.getBytes();
String s = new String(content);
log.info ("size:"+multipartFile.getSize());
Output:
size:10066
log.info ("content type:"+multipartFile.getContentType());
Output:
content type:application/vnd.openxmlformats-officedocument.wordprocessingml.document
log.info("Filename:"+multipartFile.getOriginalFilename());
Output:
Filename:prabhat-resume.docx
I want to save it in the database as a TEX开发者_如何学GoT blob. What do I need to do?
You can easily create a new File and transfer a MultipartFile object to it. There is even a method provided to make this easy.
MultipartFile multipartFile = employee.getFile();
File localFile = new File("location/"+multipartFile.getOriginalFilename());
multipartFile.transferTo(localFile);
From there you can store the location of the localFile to your MySQL database.
精彩评论