Introduction
In one of my recent developments that I had to do, we need to send Binary data of Attachments to a HTTP Adapter. The API from the provider worked seamlessly in postman but when sending the data over SAP Integration Suite / Cloud Integration HTTP Adapter even though we could see the payload Ok in the trace, the Attachment / API in the Target system was identifying it as a 0 sized Payload.
After spending days trying to figure out why this worked stand-alone in Postman and did not work in CPI, I ended up using a HTTP Tracing tool and noticed that CPI HTTP Adapter was missing the “Content-Length” header. See below a comparison of the request from Postman and from CPI.

HTTP Adapter and Chunked Transfer Encoding
Ofcourse now that I could identify the Content-Length header missing in SAP CPI HTTP Adapter, I could understand that “something was not quite right”. A dig in to SAPs Documentation on the HTTP Adapter gave us the hint to the issue. See link: HTTP Receiver Adapter. As SAP states in the documentation “The adapter can process payloads having an attachment or MIME multipart messages that are converted to byte array via script steps. For target systems that supports chunked transfer, you need not convert the payload to a byte array. “.
This was my exact issue -> I had a target System that that did not support Chunked Transfer and I was handling Attachments in my Flow. SAP states in their documentation that the payload needs to be converted to a Byte Array via Script Steps but of course does not provide the code for it.
After spending sometime debating with ChatGPT, I could figure out the solution and here is the Script that decodes my Base64 payload, converts to a Byte Array and calculates the Content Length.
Groovy Script to the Rescue
import com.sap.gateway.ip.core.customdev.util.Message
import java.util.Base64
def Message processData(Message message) {
// Retrieve Base64 payload from the message body
def base64Payload = message.getBody(String)
// Decode the Base64 payload to a byte array, using the MIME decoder to handle newlines
byte[] decodedBytes = Base64.mimeDecoder.decode(base64Payload)
// Calculate the content length
int contentLength = decodedBytes.length
// Set the Content-Length header
message.setHeader("Content-Length", contentLength.toString())
// Set the decoded byte array as the new message body
message.setBody(decodedBytes)
return message
}
This along with allowing Content-Length header in my HTTP Adapter solved the trick.
Conclusion
The devil is in the details they say, and while most “systems” support Chunked Transfer, it is essential to know that if your target System does not support Chunked Transfer, you need to convert the Payload as a Byte Array in SAP IS and set that as your Message Body!