Search code examples
javadatabasespring-bootmultipartform-dataput

@Put Mapping For An Image


I'm creating an image uploader with springboot, my entity has the employeeName, employeeDiscpretion and his photo, When you upload the photo, directly it name, path, type and size gets saved in the db! I want to be able to update the photo for a random chosen employee, when needed but I don't know how. I can delete the whole column and rewrite everything but I just want to update the photo.


Solution

  • Instead of saving the whole contents of the form-upload, you could just take the file-contents (image bytes in this case) encode them as base64 and save that base64 encoded string in your database. Whenever you want to update the image of the employee, just replace the old base64-encoded image with the new one.