I have a Spring MVC application which has a registration form. This form has a picture in the format of base64 data. I would like to store this data in the database. Presently i am storing the base64 data in an input element. I have a few questions regarding this;
-
what html element should i hold the base64 data in presently i am using an input element however i am getting an error on insert (Blob is the data type used in the Database and the Java object) –
Failed to convert property value of type java.lang.String to required type java.sql.Blob for property photo; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.sql.Blob] for property photo: no matching editors or conversion strategy foundOR is there a way to convert String To BLOB in java
-
Do i still need to use enctype=”multipart/form-data” on the form tag even thought the data is in base64?
-
If the base64 data is stored in held in html file element how do i preform validation on that to check if it is NULL?
You can use
LobHelperto convert it to aBlob. You get the LobHelper from your hibernate sessionSession.getLobHelper().As long as you don’t have an
<input type="file" />, there should be no need for enctype=”multipart/form-data”.Validation should work as on ordinary String properties with @NotNull.
Personally I wouldn’t store it encoded.