Я получаю данные от MySQL
до node-dj
, как в следующем примере:
{"image":{"type":"Buffer","data":[91,111,98,106,101,99,116,32,79,98,106,101,99,116,93]}}
Как преобразовать файл image
в Angular 7
const express = require('express');
const database = require('../modal/database');
const expressFileUploader = require('express-fileupload');
const app = express();
const promise = require('promise');
const ip = process.env.ip;
const port = process.env.port || 2000;
const bodyParser = require('body-parser');
const cors = require('cors');
app.use(cors());
app.use(expressFileUploader());
app.use(bodyParser.json());
app.post('/image',(req,res)=>{
let params = {
image:req.files.image,
description:req.body.description
}
let sql = "insert into imagelist set ?";
let sql2 = "select * from imagelist";
new promise((resolve,reject)=>{
database.mysqlConnection.query(sql,params,(err,result)=>{
if(err) throw err;
resolve(result);
});
}).then(data=>{
database.mysqlConnection.query(sql2,(err,result)=>{
if(err) throw err;
res.send(result);
});
})
});
app.get('/listofimage',(req,res)=>{
let sql2 = "select * from imagelist"
database.mysqlConnection.query(sql2,(err,result)=>{
if(err) throw err;
res.send(result);enter code here
});
});
app.listen(port,()=>{
console.log('http://localhost:'+port);`enter code here`
});