How to decode the param values received which were received as Base64 encoded form and insert into database ?
This is what i have tried.
base64
encoding is done hereI am using this code at present :
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'));
});
What i am trying to do !
image
and string
as two param valuesHow to modify my posted Express code !
Thanks !
You can retrieve the image
parameter using request.params
and then create a Buffer object, specify the base64
encoding and then convert it using the .toString()
method.
app.post('/Name/', function(request, response, next){
var image = new Buffer(request.params.image, 'base64').toString('binary');
// do the database insert...
});