0

I have a jsp page with a form. In the form I have an input of type file, and the user is able to upload an image.

when validating the form, I have a controller that should inserts the image in the database as BLOB, but I couldn't do it.

I tried getting it using:

@RequestParam byte[] img

and then:

Blob imgB = new javax.sql.rowset.serial.SerialBlob(imgb);

but it didn't work.

I tried also:

@RequestParam File img

but I've got an error message saying I can't get it as File.

Thanks in advance

Simo03
  • 273
  • 3
  • 10
  • 21
  • You are using hibernate just create an entity which has a field of type `byte[]` and annotate it with `@Lob`. To receive files you need to enable spring multipart file upload . – M. Deinum Dec 23 '14 at 19:06
  • ok, and how to enable spring multipart file upload ? – Simo03 Dec 23 '14 at 19:14
  • Just add a `MultipartResolver` as explained in [the reference guide](http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-multipart). – M. Deinum Dec 23 '14 at 19:17
  • Now I'm getting the error: The current request is not a multipart request – Simo03 Dec 23 '14 at 19:43
  • Make sure you are setting the correct content type in the form. I strongly suggest reading up on how to do file uploads. – M. Deinum Dec 23 '14 at 19:55
  • http://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean take a look – Ghokun Dec 23 '14 at 22:16
  • Thanks all, the problem is resolved ! – Simo03 Dec 24 '14 at 07:37

0 Answers0