我正在使用API并从https://www.qrcode-monkey.com/中提取示例,并将其放在我的nodeJs上 我使用缓冲区解码响应,但是失败了:
<html>
<head></head>
<body>
<img src="data:image/png:base64,/VBO...QH9/Vlx/f3ZAAAAAElFTkT90mD9"> == $0
</body>
</html>
这是我的代码
const express = require("express");
var router = express.Router();
var unirest = require("unirest");
router.get('/api/qrpicture',(req,res) => {
var req = unirest("POST","https://qrcode-monkey.p.rapidapi.com/qr/custom");
req.headers({
"x-rapidapi-host": "qrcode-monkey.p.rapidapi.com","x-rapidapi-key": "my-key","content-type": "application/json","accept": "application/json"
});
req.type("json");
req.send({
"data":"https://www.qrcode-monkey.com","config":{
"body":"rounded-pointed"
},"size":300,"download":false,"file":"png"
});
req.end(function (d) {
if (d.error) throw new Error(d.error);
var encodedImage = new Buffer.from(d.body,'binary').toString('base64');
res.end("<html><body>" +
"<img src=\"data:image/png;base64," + encodedImage + "\" />" +
"</body></html>");
});
});
module.exports = router;
如何解码来自QR码猴子API的二进制数据?