Buffer to string

Hi, I'm having a bit of a problem posting data to a REST API.
I can't post the data as buffer, I have to post it as a string.

This has led up to some testing.....
I'm trying to open a locally stored PDF by using the "file-in" node.
I'm fetching the content as "single buffer object" I then try to convert the buffer to string by using buffer.toString(), tested this by using encoding utf-8 and latin1, after that I write the string to a destinationfile. The thing is that the destinationfile is destroyed and I can't really get what I have to do to keep the string intact, I guess something gets destroyed when converting to string.

Anyone with ideas or input on this?

pasting sample flow:
[{"id":"9495208.57a77e","type":"file in","z":"f94d5a4b.3ceeb8","name":"getFile","filename":"example_2page.pdf","format":"","chunk":false,"sendError":false,"encoding":"utf8","x":2050,"y":1060,"wires":[["53811629.bd5098"]]},{"id":"7febb7ef.2189d8","type":"file","z":"f94d5a4b.3ceeb8","name":"saveTo","filename":"example_2page_copy.pdf","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":2350,"y":1060,"wires":[]},{"id":"e153c330.00e75","type":"inject","z":"f94d5a4b.3ceeb8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1890,"y":1060,"wires":[["9495208.57a77e"]]},{"id":"53811629.bd5098","type":"function","z":"f94d5a4b.3ceeb8","name":"","func":"msg.payload = msg.payload.toString('latin1');\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2150,"y":960,"wires":[["7febb7ef.2189d8"]]}]

That doesn't make sense - pdf is a binary file so yes just turning into a string will most likely break it. The API would either need to accept a binary blob (often called octet-stream) or maybe it could be base64 encoded ? Or maybe you need to extract the actual text from the document first and just send that ? Most odd.

1 Like

Ok, so I'm obviously missing out on something here.
I guess I have to contact the company with the REST API and ask them how they expect me to send the data. The documentation is some what "thin".
Or my competence in the area are most likely inadequate :slight_smile:
Thank you dceejay!!

I will further dig in to this i guess...


Is the api public? We may help better if you share it or any error messages you are getting

Unfortunately not public. :frowning:

The thing is that the only error message I'm getting is that i need to be logged in to do the operation.
The authentication is Amazon HMAC-style, making it pretty much impossible for me to understand what goes wrong since when trying to send the file directly as buffer it fails with failed login.
But I will do some more experimenting to see if I can get it working..


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