Upload a base64 Image through a REST post request(From microflow or Postman)

0
Hello,   I exposed a System.Image entity as a REST resource.  Using the builtin swagger commands, I can just use the POST action by selecting manually an image to upload. This is not very interesting to use a REST API with a manual action, so I used Postman for the POST request using a base64 text as the content of the image.   I tried different way to fill in the body but I don’t find the right combination:  JSON [   {     "Contents": "iVBORw0KGgoAAAANSUhEUgAAAFoAAABaCAYAAAA4qEECAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABDeSURBVHhe7V35b11HFY6fn/c0duwsdmLHcWonXSi4FCqgpS2hDRAKgl/4A0BFCNSittAKBBWqVCpoUVWQWpU/gZ8qhGgT0lI20V+AhFK6JrXj7E5ix/FuP5vvG84Mc+fdd+/c+5a8Z3ql0bvLzJlzvjlz5sz66taV+FpdXa1zSdbV1a0Wm43QJW1NnzRXS0g7wGIp6NoEM8UCUOH0ClwrVDj79NnlaV96UuVP6daWUmtd+SV4P4eyI1BRjbY0Uudr21wtrLbniWxwiA13ZdMmh/moPCpZIyoNNNsE5slfHTTYGuAVASInvytxgAjImna9lYfC07LppK0DG1LeV+SqGNAWGAQki0BAGDRAWuOa8G4TQqcANIXfRYRZBH5jvGWANBKGEPLZZdFfwr1Oz3QsPIZlDXhcIZaqFFIDnbRhkvgEliA3SOA9gb5WAHwXgp9AXALNcAnPp0shLGj2SOFN4PeigJ2LAzqpnIV4TQV0iK2N9WcljQaZmjlMpiDo7/mrwcXzmz7AIj4LawOCLjzSnkf6c256xN2Cdy2izdTyOYRtCOOIfyEqP8v2KzaF58T9glRACzBuQxYJtjBMc/AhhLdFc0mjlDKCa+Gk2a”   } ] XML  <ImgStorages>     <ImgStorage>         <Contents>iVBORw0KGgoAAAANSUhEUgAAAFoAAABaCAYAAAA4qEECAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABDeSURBV </Contents> </ImgStorage> </ImgStorages>   Plain text(with single, double quote or nothing...) iVBORw0KGgoAAAANSUhEUgAAAFoAAABaCAYAAAA4qEECAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABDeSURBV   Nothing works. Actually, the request send a 201 code and a new entry is added in the entity, but it is not the image. The content is not filled in or filled in with a base64 code that does not correspond to the initial one… Also, I don’t find any documentation to use the microflow operation “Call REST” to call an internal POST for System.Image or System.FileDocument entities. If you can share how you can use a base64 text as an input to create an image or a file through the use of the proper microflow operation, I will be very interested too.   Any ideas will be welcome.   Thank you.
asked
1 answers
0

Hi,

  1. Ensure you have set up your REST API properly in Mendix with the appropriate POST operation to create an image. Make sure that the API definition aligns with the structure you're trying to send.

  2. In Postman, create a new POST request and specify the URL for the REST API endpoint.

    Set the Content-Type header to application/json (if you're using JSON data) or application/xml (if you're using XML data).

  3. In your Mendix microflow, make sure that you're handling the incoming request data correctly. Convert the base64 contents to the respective file using ‘Base64 decode to file’ 
    Base64DecodeToFile – This stores a base 64-encoded string plain in the provided target file document.
    https://docs.mendix.com/appstore/modules/community-commons-function-library/#33-files

    If you're facing issues with this step, it might be helpful to provide more details about your microflow setup.

answered