How to send a file over http as a multipart mime?
Below are the steps to do that -
1. Make sure you have the data encryption in place for data security, which is important when transferring data through network protocol.
2. Now copy the output data as blob in a variable to use it later in below section-
SET OutputRoot = InputRoot;
DECLARE Content BLOB CAST(Environment.TGCSARC.FILEDATA AS BLOB);
3. Set the required authentication/authorization headers for backend -
SET OutputRoot.HTTPRequestHeader."Authorization" = 'Basic '|| Base64-encoded (ID:PASS);
SET OutputRoot.HTTPRequestHeader."Date" = CAST(CURRENT_TIMESTAMP AS CHARACTER FORMAT 'yyyyMMddHHmmss');
SET OutputRoot.HTTPRequestHeader."Host" = Backend-HOST;
Note : ID:PASS should be encoded in base 64
4. Set Headers for content type -
SET OutputRoot.Properties.ContentType = 'multipart/form-data; boundary=' || UUIDASCHAR;
SET OutputRoot.HTTPRequestHeader.Accept = '*/*';
5. Now create output message domain as MIME and add data like below -
CREATE LASTCHILD OF OutputRoot DOMAIN('MIME');
CREATE LASTCHILD OF OutputRoot.MIME TYPE Name NAME 'Parts';
CREATE LASTCHILD OF OutputRoot.MIME.Parts TYPE Name NAME 'Part';
DECLARE P1 REFERENCE TO OutputRoot.MIME.Parts.Part;
CREATE FIELD P1."Content-Type" TYPE NameValue VALUE 'text/plain';
CREATE FIELD P1."Content-Disposition" TYPE NameValue VALUE 'form-data; name="file"; filename="' || Environment.Variables.InputFileName || '"';
CREATE LASTCHILD OF P1 TYPE Name NAME 'Data';
CREATE LASTCHILD OF P1.Data DOMAIN('BLOB') PARSE(Content);
6. Now set the target URL and method to post and propagate to out terminal -
SET OutputLocalEnvironment.Destination.HTTP.RequestURL = Target-Endpont;
SET OutputLocalEnvironment.Destination.HTTP.RequestLine.Method = 'POST';
PROPAGATE TO TERMINAL 'out';