Is there any flow variable that holds the size of payload of incoming request in Apigee? I know there is the Content-Length header, but I need to calculate the size in bytes/MBs. If there isn't any flow variable, how else can I calculate the payload size in Apigee. Any suggestions to achieve this in Apigee JS policy?
The content-length header provides that information. I don't understand what you mean when you say
I know there is the Content-Length header, but I need to calculate the size in bytes/MBs.
Why is there a "but" in your statement above? Why is it not acceptable for you to just use content-length?
If the Transfer-Encoding is chunked, then content-length is usually not present, and even if it is present, you should ignore it. So when using chunked transfer-encoding, it is not possible to know the length of the content until you receive all the chunks. You could do this in Apigee by making sure that streaming is turned off, and then "measuring" the length of the content in a JS, Python, or Java step.
I am implementing logging on API proxies. The requirement is to log request and response payloads along with some flow variables. However, according to this link the log payload must not exceed 256KB.
I am planning to store request content in flow variable and referring it in log payload of message logging policy. I want to make sure that the overall log payload size would stay in limit.