I want to send multipart/form-data from client via nodejs server to postgresql In nodejs I am using express-form-data module. server code:
var formData = require("express-form-data");
var BodyParser=require('body-parser');app.use(BodyParser.json()).use(formData.parse()).use(formData.format()).use(formData.stream()).use(formData.union());
app.post('/create-user',function(req,res){
var username=req.body.username;
var password=req.body.password;
..........................
var img=(req.files.pic).toString('HEX')+'\\x';
pool.query('INSERT into "Users" (username,password,"full
name","D.O.B",emailid,sex,img) VALUES ($1,$2,$3,$4,$5,$6,$7)',
[username,hashpass,name,dob,email,sex,img],function(err,result){ if (err) {
res.status(500).send(err.toString());
Its obvious i have set bytea type for image data. I am tried this skiping image input and all other fields were inserted sucessfully. But i dont get the logic of inserting the image to postgres. I hav searched other stackoverflow answers nowhere i could find how to convert the image data to bytea type.My database and nodejs is set to UTF8 encoding. on converting img to hex string as shown in the code snippet i get error: invalid input syntax for type bytea
if no conversion done errors like: database server refuses to connect,nodejs console says cant set headers after they are sent.