我想通过JavaScript将“ base64”字符串转换为字节数组。
我收到了类似URL的字符串。
("data:image/jpeg;base64,/9j/4QN6RXhpZgAASUkqAAgAAAAIA)
Run Code Online (Sandbox Code Playgroud)
而且我想将字符串转换为字节数组。因为我需要此字节数组来发送Rest API端点。其余的API Content-type = application / octet-stream。
我已经从服务器以字节数组的形式发送了图像文件。现在我必须将其转换为jpeg文件并将其显示在网页中。
代码:
app.get('/getPhoto/:hash',function(req, res){
console.log(req.params.hash);
invoke = require('/Users/sanjeev.natarajan/ipfs/file1.js');
invoke.getfile(req.params.hash).then((str)=>{
console.log("resu",str)
res.send({"Result":str});
})
.catch((error) => {
res.send({"Error":"error in fetching the file through the hashcode"});
})
});
Run Code Online (Sandbox Code Playgroud)
我正在从后端接收数据;现在我需要将其转换为 angular6 中的图像