如何解码收到的以Base64编码形式接收并插入数据库的参数值?
这是我尝试过的。
base64
编码我目前正在使用此代码:
var express = require('express')
, async = require('async')
, http = require('http')
, mysql = require('mysql');
var app = express();
var connection = mysql.createConnection({
host: 'localhost',
user: '******',
password: "******",
database: 'posting_information_DB'
});
connection.connect();
// all environments
app.set('port', process.env.PORT || 1234);
app.use(express.static(__dirname + '/public/images'));
app.post('/Name/',function(request,response,next){
app.use(express.bodyParser());
var keyName=request.query.Key;
var name_of_restaurants;
async.series( [
function(callback) {
connection.query('INSERT INTO details (name) VALUES (?)', [keyName], function (err, rows, fields)
{
console.log('Connection result error ' + err);
callback();
});
}
// Send the response
] );
} );
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
我想做什么!
image
和string
作为两个参数值如何修改我发布的Express代码!
谢谢!
答案 0 :(得分:1)
您可以使用request.params
检索image
参数,然后创建Buffer object, specify the base64
encoding,然后使用.toString()
方法对其进行转换。
app.post('/Name/', function(request, response, next){
var image = new Buffer(request.params.image, 'base64').toString('binary');
// do the database insert...
});