[英]Using base64 function results in InvalidCharacterError
What I want to do is using base-64
module method, in my node.js + express project. 我想做的是在我的node.js + express项目中使用
base-64
模块方法。
The code is like this. 代码是这样的。
router.get('/list', function(req, res, next) {
client.query('SELECT * FROM Document',function(err, row){
if(err) throw err;
var base64 = require('base-64');
row.forEach(e => {
e.text = base64.decode(e.text);
});
res.render('main/list',{title:"###", row:row});
})
});
In this function, there are MySQL query in the callback. 在此函数中,回调中有MySQL查询。
The text
is the base-64 encoded value of the Database. text
是数据库的base-64编码值。
But, the base64.encode()
doesn't work in this code, but results in InvalidCharacterError
但是,
base64.encode()
在此代码中不起作用,但会导致InvalidCharacterError
how should I use correctly? 我应该如何正确使用?
You can use nodejs built-in functions 您可以使用nodejs内置函数
let original = 'abcdefrgsdfdsf123123123123';
let testCode64 = Buffer.from(original).toString('base64')
let testDecode64 = Buffer.from(testCode64, 'base64').toString('utf-8');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.