I am trying to POST the image from the REST Client to the server. After the new entity is created in the database, the contents of the image field look like it is saved successfully but when I try to visualize, it i get some error.
Here are the steps taken:
-
Mobile APP (client side)
Converted the image into String in my flutter app.List<int> imageBytes = fileSelected.readAsBytesSync(); String _base64Image = base64Encode(imageBytes);
-
CUBA APP (server-side)
if(imageAttach!=null) { leaveApplication.setLeaveApplicationDoc(new ArrayList<>()); LeaveApplicationDoc applicationDoc = metadata.create(LeaveApplicationDoc.class); // decode the string and write to file byte[] decodedBytes = Base64 .getDecoder() .decode(imageAttach); applicationDoc.setFileImage(decodedBytes); applicationDoc.setLeaveApplication(leaveApplication); leaveApplication.getLeaveApplicationDoc().add(applicationDoc); em.persist(applicationDoc); } em.persist(leaveApplication);
I have checked the documentation but didn’t see anything related to saving the image files from REST client. (note, this is not implemmentation of File Descriptors but image file - byteArray) I might have been missing something, thanks for your help.