0
Well I have this table:
And I have this code that I get an image by the woman in the nodejs:
routes.post('/salvarImagem', upload.single('Img') , (req, res) => {
const connection = mysql.createConnection({
host : 'localhost',
port : 3306,
user : 'root',
password : '',
database : 'jubart'
});
var query = "INSERT INTO tb_imagens (FK_Portifolio, Imagem, Nome, Tipo, Tamanho) VALUES (" + req.body.Portifolio + ", BINARY(" + req.file.buffer.toString('binary') + "), '" + req.file.originalname + "', '" + req.file.mimetype + "', '" + req.file.size + "')";
connection.query(query, function(error, results, fields){
if(error)
res.json(error);
else{
res.json(results);
}
connection.end();
});
});
It saves but the image it saves wrong it does not save as binary file but rather a file with Base64 written and when I return from the database I can not display the image. Does anyone know how I convert req.file.buffer to blob format for saving?
Ever tried to replace
BINARY(" + req.file.buffer.toString('binary') + ")
for" + req.file.buffer + ")
?– Valdeir Psr
Yes and so n salva
– Igor De Moraes Sampaio