Handling images in REST API

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:

  1. Mobile APP (client side)
    Converted the image into String in my flutter app.

    List<int> imageBytes = fileSelected.readAsBytesSync();
    String  _base64Image = base64Encode(imageBytes);
    
  2. 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.

This returning error:

2022-04-22 07:20:34.501 ERROR [http-nio-8080-exec-326/inteaccERP-core/001353] com.haulmont.cuba.core.sys.ServiceInterceptor - Exception: 
java.lang.IllegalArgumentException: Illegal base64 character 20
	at java.base/java.util.Base64$Decoder.decode0(Base64.java:746) ~[na:na]
	at java.base/java.util.Base64$Decoder.decode(Base64.java:538) ~[na:na]
	at java.base/java.util.Base64$Decoder.decode(Base64.java:561) ~[na:na]
	at com.inteacc.erp.service.LeaveSystemServiceBean.createLeaveApplication(LeaveSystemServiceBean.java:1870) ~[inteaccERP-core-2021.01-SNAPSHOT.jar:na]

the line 1870 is :
.decode(imageAttach);

Does this indicate the image converted into string is not compatible with REST?