Thank you very much for this. I have tried with the below code and it worked for me.
var hm = require('header-metadata');
session.input.readAsBuffer(function (error, buffer) {
if (error)
{
session.output.write (error.errorMessage);
} else {
//Create a boundary
var boundary = "xyz123";
//Line break syntax
var crlf = '\r\n';
//Create the multipart message payload
var multipart = '--' + boundary + crlf +
'Content-Disposition: form-data; name="file"; filename="payload.txt"' + crlf +
'Content-Type: text/plain' + 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 in http requst header
hm.current.set('Content-Type', contentType);
//Write the output payload
session.output.write(multipart);
}
});
Thanks,
Debarpan
------------------------------
Debarpan Mukhopadhyay
------------------------------
Original Message:
Sent: Thu March 16, 2023 04:34 AM
From: Hermanni Pernaa
Subject: Send multipart/form-data in XST
Hi,
haven't done this using XSLT because using GWScript is a lot easier. Anyway, just check that you have all the boundaries etc, in place. Here is an example GWScript for creating a multipart/related message "manually" to get an idea on the structure of the message. The message is a SWA but if you'll strip the SOAP message part it should be ok.
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
var boundary = "xyz123";
//Line break
var crlf = '\r\n';
//Create a soap message payload
var soap_message = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><foo>the soap message body part goes here</foo></soapenv:Body></soapenv:Envelope>';
//Create the multipart message payload
var multipart = '--' + boundary + crlf +
'Content-Type: text/xml' + crlf + crlf +
soap_message + crlf + '--' + boundary + crlf +
'Content-Type: application/zip' + crlf +
'Content-Transfer-Encoding: base64' + crlf +
'Content-ID: <myattachment>' + crlf + crlf +
buffer.toString('base64') + crlf + '--' + boundary + '--' + crlf;
//Concatenate a new content-type header value
var contentType = 'multipart/related; boundary=' + boundary + ' type="text/xml"';
//Set the content type header created above
hm.current.set('Content-Type', contentType);
//Write payload into output
session.output.write(multipart);
}
});
------------------------------
Hermanni Pernaa
------------------------------