2016-10-14 42 views
1
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格式,必須閱讀並沒有在數據庫中存儲顯示上傳的圖片。如何使用JSON文件轉換爲圖像節點JS

+0

讓我看看你的json ... – Thalaivar

回答

0

您需要將其轉換爲base64字符串。

var jsonContent = JSON.parse(jsonData); 
var buff = new Buffer(jsonContent).toString("base64"); 
+0

是的,我做到了。 。 –

相關問題