We have a user input form which contains input file (image) selection. When user submits the form, we want to read the file selected by user and store it as base 64 encoded data. We have following code to do the same. This code gets executed when the form is submitted.
//Read image data from slingRequest
String userImage1 = slingRequest.getParameter("userImage1");
//Apply base 64 encoding on the data received in slingRequest
String encodedUserFile = "";
byte userFileBytes = userImage1.getBytes();
encodedUserFile = Base64.encodeBase64String(userFileBytes);
These statements are not throwing any error. But, when I try to apply base 64 decoding on the contents available in 'encodedUserFile', its' not the image user uploaded. There seems to be some problem, which I am not able to figure out. Can someone please help me with this?
You need to use the Sling RequestParameter interface to get an uploaded file.