2

I have a question. I'm working on a Spring web MVC project where I need to upload an image, convert it to base64 and then write it to a mysql database. I'm very new to spring and I've searched the web finding a lot of tutorials that just don't really fit my answer. I basically don't know where to start..do I use javascript to do this in the jsp file? Or is it better to use java? I literally have no idea where to start, it sounds difficult to me but I'm sure there is a very easy way to do this. I just have to get used to spring a little bit more. Can someone please point me in a direction about how to do this? Also, I'm using annotations and no xml.

Thanks in advance!

1oneSquared
  • 113
  • 2
  • 7

1 Answers1

1

Create Spring controller and send image file as multipart request to that controller, then convert image to base64 in java.

See this

Community
  • 1
  • 1
Vikas Jaiswal
  • 66
  • 1
  • 4
  • Thank you, I'm just a little bit unsure about where to do what. Do I encode to base64 in the controller? And in what file do I send it to the database? – 1oneSquared Oct 19 '16 at 12:22
  • first use multipart to get file in controller [learn from this] (https://spring.io/guides/gs/uploading-files/) – Vikas Jaiswal Oct 19 '16 at 12:29
  • In controller you will get byte from multipart object and convert it into base64 string and store this string into database. – Vikas Jaiswal Oct 19 '16 at 12:36