I have a webhook node that brings in a set of office document files (typically .xlsx or .doc). I need to store them in a Postgres Database for further processing. How to send a binary file to a Postgres row?
(I have created the table with bytea data type. If I need to modify it, pls mention)
Also, when we Select (query) the rows from the DB, will we get the binary file too?
Hi @Jayavel, the exact approach will of course depend on how your incoming data looks like, but assuming you are having a binary item named data coming from your webhook something like below would let you insert a binary file into a bytea column.
Table schema
Table "public.uploads"
Column | Type | Collation | Nullable | Default
------------+-----------------------------+-----------+----------+-------------------------------------
id | integer | | not null | nextval('uploads_id_seq'::regclass)
created_at | timestamp without time zone | | not null | now()
data | bytea | | |
Indexes:
"uploads_pkey" PRIMARY KEY, btree (id)
Workflow
This example uses the Move Binary Data node to create a base64 string based on the binary data:
I’ve used an image file here to illustrate the function, but of course this will work for other file types too. When processing different file types you probably want to keep a record of the filename as well as the MIME type though.