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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With