Following this question- https://www.googlecloudcommunity.com/gc/Apigee/How-to-get-the-response-and-request-size-and-log-it/m...
As I wrote: I'd like to get the request body size in bytes- and I might not get the 'content-length' header.
As the 'request.content' variable returns a String, I tried using the Blob API to get the bytes size of it (https://www.geeksforgeeks.org/how-to-get-the-length-of-a-string-in-bytes-in-javascript/)- but I'm getting the error: "ReferenceError: \"Blob\" is not defined. "detail":{"errorcode":"steps.javascript.ScriptExecutionFailed"}:
var size = new Blob([request.content]).size;
Could you suggest why the Blob is not working and how to get the size of the body? Thanks
In the end I used this way- which works for UTF-8 encoding (would like to hear if there is more general way):
function byteCount(s) {
return (encodeURI(s).split(/%..|./).length - 1).toFixed(0);
}