Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert multipartfile into Blob type

Tags:

hibernate

Hi I am working with saving Image into DB,I am Taking Image as Multipart and trying to convert into Blob type. I do this method:

Blob blob=Hibernate.getLobCreator(sessionFactory.getCurrentSession()).createBlob(multipartFile.getInputStream(),multipartFile.getSize());

But getting Nullpointer Exception While Executing. the file is Unable to convert multipart into Blob, any other Method to saving Image into DB.

like image 839
Ankit Tater Avatar asked Aug 06 '13 07:08

Ankit Tater


People also ask

What is MultipartFile?

A representation of an uploaded file received in a multipart request. The file contents are either stored in memory or temporarily on disk. In either case, the user is responsible for copying file contents to a session-level or persistent store as and if desired.

How do you create a multipart file from a byte array?

Use the default CommonsMultipartFile where you to use the FileDiskItem object to create it. Example: FileItem fileItem = new DiskFileItem("fileData", "application/pdf",true, outputFile. getName(), 100000000, new java.


1 Answers

MultipartFile savedFile;
savedFile=itemView.getImgFile();//file from model attribute 
Blob blob=Hibernate.createBlob(savedFile.getInputStream()); // hibernate method for create blob 
//Save method will be call here 

http://viralpatel.net/blogs/tutorial-save-get-blob-object-spring-3-mvc-hibernate/ i followed above tutorial

like image 126
Hardik Gajjar Avatar answered Oct 04 '22 07:10

Hardik Gajjar