HTTP IN node (POST) truncating body

Hello!

The issue:
It seems the HTTP IN node is truncating the body if it's too large. When I attempt to
JSON.parse(msg.payload.files)
I get SyntaxError: Unexpected token ' in JSON at position 1
Which makes sense, since msg.payload.files is truncated.

Details
I have an https in endpoint that is open to my carrier (VoIP)

This endpoint accepts two types of data, SMS and MMS. I have a switch node added to switch between
msg.payload.type ('incomingWebhookSMS' or 'incomingWebhookMMS')

The data that my carrier sends me is this format:

SMS

{
    "type": "incomingWebhookSMS",
    "destination_number": "XXXXXXXXXX",
    "caller_id_number": "XXXXXXXXXX",
    "text": "Hello world!"
}

MMS

{
    "type": "incomingWebhookMMS",
    "to": "XXXXXXXXXX",
    "from": "XXXXXXXXXX",
    "text": "",
    "files": "{'d3c4090f-d23f-4945-8f44-faee2fb7af3c_123_1.jpeg': '/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAUDBAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChALCAgOCQgIDRUNDhERExMTCAsWGBYSGBASExIBBQUFCAcIDwkJDxIPDw8SEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEv/AABEICtoFBAMBIgACEQEDEQH/xAAdAAEAAAcBAQAAAAAAAAAAAAAAAgMEBQYHCAEJ/8QAbhAAAQMCAQYIBgoKDQcKBQIHAQACAwQRBQYSEyExUQcIFEFhkaHRIjJScYGxFSNCU2JyksHS4RYzNXSCk7KztPAJGCQ0NlRVc3WUosLTF0OVo8PU1SVERWNkg4SFxPEmN6SlteNW4nbFRmblZf/EABwBAQADAQEBAQEAAAAAAAAAAAABAgMEBQYHCP/EAEgRAQABAwEEBggEBAMGBQUBAQABAgMRBBIhMVEFE0FhcZEUIjJSgaGx0RUzwfA0QnLhBiOyYnOCkqLxB0NTY8IWJCWz4tJ0/9oADAMBAAIRAxEAPwDeyIi818uzWkkz42O8pjT6SBdTVb8n5M6Bvw...",
    "destination_number": "XXXXXXXXXX",
    "caller_id_number": "XXXXXXXXXX"
}

As you can see, "files" is being truncated. How can I fix this?

Things I have tried
I have set

/** The maximum size of HTTP request that will be accepted by the runtime api.
     * Default: 5mb
     */
    apiMaxLength: '1000mb',

I started out with 50mb, then 100mb, and 1000mb and still no luck.

Thanks for reading!

msg.payload.file is not truncated it is just shown that way in th debug sidebar, to save overheads of displaying large values.
send it to console using debug node and you will see it all.

The error you get is that msg.payload.file is not a json, it is more likely to be a binary format or base64 encoded. You need to work out what format the api sends the image in.

I didn't think to console log it.

I'll do that now.

But my js is identical to my prod node.js server. I am just moving all that code off my prod nodejs to node-red. Node-RED is way to awesome to be handjobing all this code haha.

One other thing, the headers from the http in node should give a clue to the file format is. Set the debug node to complete message object to see all the data

Looking again msg.files has single quotes which is not valid JSON, try replacing them with double quotes.

Yup.. missed that when moving my code over.

const filesObject = JSON.parse(msg.payload.files.replace(/'/g, '"'))

All good now :face_holding_back_tears:!

Console log showed full body too.

Node-RED is so awesome haha. I feel like I am cheating!

I started this little repo a couple of days ago

4 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.