我正在使用ipfs-http-client来读取文件表单infura的内容,如何使用"cat“函数来正确地获取字符串/json格式的数据?
const client = create({
url: ipfsUrl(),
headers: {
authorization: ipfsAuthPhrase(),
},
});
const cidformat = "f" + cid.substring(2);
const cidV0 = new CID(cidformat).toV0().toString();
const resp = await client.cat(cidV0);
let content = [];
for await (const chunk of resp) {
content = [...content, ...chunk];
}
console.log(content.toString());现在,我只是在控制台日志上得到一个二进制文件数组。
发布于 2022-05-18 11:16:45
从现在开始,这仅仅是解码content缓冲区的问题。
如果内容是一些JSON:
const raw = Buffer.from(content).toString('utf8')
console.log(JSON.parse(raw))如果内容是图像:
Buffer.from(content).toString('base64')https://stackoverflow.com/questions/70979793
复制相似问题