webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Convert base64 encoded string back to image in flow

  • 1.  Convert base64 encoded string back to image in flow

    Posted Thu April 14, 2016 06:16 AM

    I have received a base64 encoded image from source system via REST post.
    I need to convert this back to an image and write on the file system of the IS.

    How do I generate back the image from a string of the based64 encoded image?
    Any suggestions?


    #webMethods
    #webMethods-General
    #Integration-Server-and-ESB


  • 2.  RE: Convert base64 encoded string back to image in flow

    Posted Thu April 14, 2016 06:49 AM

    You can use “pub.string:base64Decode” service to convert inbound base64Encoded string to byte array and then you can use one of the below approaches:

    1. If proper allowAccess permissions are setup on the IS to target file path then you can use “pub.file:bytesToFile” to write the above byte array to file

    OR

    1. write some simple java service (below is a sample code snippet) to write the byte array to file system.
    FileOutputStream fos = new FileOutputStream("pathname");
    fos.write(myByteArray);
    fos.close();

    #Integration-Server-and-ESB
    #webMethods-General
    #webMethods


  • 3.  RE: Convert base64 encoded string back to image in flow

    Posted Thu April 14, 2016 07:02 AM

    Hi Prasad,

    I have gone with this approach suggested by you,

    1. If proper allowAccess permissions are setup on the IS to target file path then you can use “pub.file:bytesToFile” to write the above byte array to file

    But when I open the tif image created in this way, it says it is not a valid image.

    When I compare the base64 Encoded string which was initially sent by source system, and what was received by webMethods via Rest post, I see some addition ‘+’ signs added at the end of each line of the string.

    Any comments, further advice?


    #webMethods-General
    #webMethods
    #Integration-Server-and-ESB


  • 4.  RE: Convert base64 encoded string back to image in flow

    Posted Thu April 14, 2016 08:00 AM

    Oh yeah… you may have to ask the sender/source to URL Encode the base64EncodedString (if webMethods, use pub.string:URLEncode) and as a first step of your target service URL decode the inbound string using pub.string:URLDecode

    Hope this helps…


    #Integration-Server-and-ESB
    #webMethods-General
    #webMethods