DataPower

DataPower

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

How to send incoming payload as a file attachment from data power to backend system?

  • 1.  How to send incoming payload as a file attachment from data power to backend system?

    Posted Thu December 03, 2020 03:44 PM

    Our requirement is getting the file via FTP. The file contain full of JSON value. The file contains multiple records - each treated as one json record.SO the file has collection of json records.

    We can receive this with help of FTP/Sftp FSH. But our real issue is , we have to send the content of FTP file as a attachment to backend system [content-type: multipart/Form-data]

    How to send incoming payload as a file attachment from data power to backend system?



    #DataPower
    #Support
    #SupportMigration


  • 2.  RE: How to send incoming payload as a file attachment from data power to backend system?

    Posted Mon December 07, 2020 08:48 AM

    Hi,

    are you trying to send each one of the JSON records as separate attachments or the whole file as one?

    --HP



    #DataPower
    #Support
    #SupportMigration


  • 3.  RE: How to send incoming payload as a file attachment from data power to backend system?

    Posted Mon December 07, 2020 01:08 PM

    whole file as one, file will have multiple JSON records (bulk upload data to a 3rd party system)

    -Abhijit Ray



    #DataPower
    #Support
    #SupportMigration


  • 4.  RE: How to send incoming payload as a file attachment from data power to backend system?

    Posted Mon December 07, 2020 01:33 PM

    Ok. Maybe this GatewayScript snippet will be helpful.

    var hm = require('header-metadata');

    session.input.readAsBuffer(function (error, buffer) {

    if (error)

    {

    // handle error

    session.output.write (error.errorMessage);

    } else {

    //Create a boundary id, make sure that it isn't present in the payload

    var boundary = "xyz123";

    //Line break

    var crlf = '\r\n';

    //Create the multipart message payload

    var multipart = '--' + boundary + crlf +

    'Content-Type: text/plain' + crlf +

    'Content-Disposition: form-data; name="jsontext"; filename="bulk.json"' + crlf + crlf +

    buffer.toString() + crlf + '--' + boundary + '--' + crlf;

    //Concatenate a new content-type header value

    var contentType = 'multipart/form-data; boundary=' + boundary + ' type="text/plain"';

    //Set the content type header created above

    hm.current.set('Content-Type', contentType);

    //Write payload into output

    session.output.write(multipart);

    }

    });



    #DataPower
    #Support
    #SupportMigration