I'm running a spring web application, in which at some point the user has to input about five fields in the mysql database. For every other field everything works fine, HTML's form gets the data and then spring updates the database, despite for the blob field. This blob field has to contain an image, a picture. In the model class I'm storing it with the Blob data type. This is how am asking for the picture (with the aim of bootstrap);
<!-- Picture -->
<div class="custom-file">
<input type="file" class="custom-file-input" name="picture">
<label class="custom-file-label" for="picture">Select picture...</label>
</div>
While this is how am receiving it with the parameters;
@RequestParam(value = "picture", required = false) Blob picture
Then I update the database with JPA repository. But I get a 500 internal server error. This is the message;
Failed to convert value of type 'java.lang.String' to required type 'java.sql.Blob'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.sql.Blob': no matching editors or conversion strategy found
And then I get this exception;
org.springframework.web.method.annotation.MethodArgumentConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'java.sql.Blob'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.sql.Blob': no matching editors or conversion strategy found
I would also like to specify that if I remove the picture field and I don't add it to the database everything works fine & in the MySQL Workbench I get a blank image but everything else is there.
How may I solve this? Are there better ways of storing a Blob in spring java? +Thanks everyone.