node.js:
var express = require("express");
var myParser = require("body-parser");
var app = express();
app.use(myParser.urlencoded({limit: '50mb', extended: true}));
app.get("/",function(req,res){
res.send("Welcome");
});
app.post("/sendmessage", function(request, response) {
//console.log(request.body);
var jsonData = request.body;
console.log(jsonData);
var jsonContent = JSON.parse(JSON.stringify(jsonData));
// Get Value from JSON
//console.log(jsonContent.text);
var data = jsonContent.text;
// console.log(data);
//DB Connection
//createConnection(data);
response.send("Data Received");
});
var server = app.listen(8080, function () {
var host = "10.0.0.5";
var port = "8080";
console.log("Example app listening at http://%s:%s", host, port);
});
从客户端我使用节点js获得了json格式,但我需要读取json格式并显示上传的图像而不存储在数据库中。
答案 0 :(得分:0)
您需要将其转换为base64
字符串。
var jsonContent = JSON.parse(jsonData);
var buff = new Buffer(jsonContent).toString("base64");