【问题标题】:How do I convert my IPFS return into the original .midi or .png file using js (ipfs-http-client)?如何使用 js (ipfs-http-client) 将我的 IPFS 返回转换为原始的 .midi 或 .png 文件?
【发布时间】:2022-03-22 09:16:01
【问题描述】:

我将图像和音频文件存储在 IPFS 中。当我在 javascript 中检索内容时,我最终会得到一个 Buffer 或 tarballed header/body 输出。如何将其转换回原始文件以在网站上使用?

const audioCID = CID.parse("QmapPj7koCCMp241CAhwZV413K3FrqVnYdKC2GeTQHsCuF")
const output = await pipe(
    ipfs.get(audioCID),
    // tarballed,
    collect
)   

我得到的输出是:

output [
  <Buffer 51 6d 61 70 50 6a 37 6b 6f 43 43 4d 70 32 34 31 43 41 68 77 5a 56 34 31 33 4b 33 46 72 71 56 6e 59 64 4b 43 32 47 65 54 51 48 73 43 75 46 00 00 00 00 ... 1998 more bytes>
]

【问题讨论】:

    标签: javascript node.js ipfs


    【解决方案1】:

    输出(转换为 ASCII)是 CID:

    51 6d 61 70 50 6a 37 6b 6f 43 43 4d 70 32 34 31 43 41 68 77 5a 56 34 31 33 4b 33 46 72 71 56 6e 59 64 4b 43 32 47 034 54 75 1 47 65 54 751 4 00 00 00

    =

    QmapPj7koCCMp241CAhwZV413K3FrqVnYdKC2GeTQHsCuF

    来源:https://www.rapidtables.com/convert/number/ascii-hex-bin-dec-converter.html

    解决方案:

    需要用 ipfs.cat 获取 IPFS 文件的内容: https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#ipfscatipfspath-options

    【讨论】:

      猜你喜欢
      • 2019-12-16
      • 2021-11-26
      • 2023-01-30
      • 2023-01-13
      • 2023-03-03
      • 2022-01-21
      • 2018-02-28
      • 2020-10-20
      • 2021-03-12
      相关资源
      最近更新 更多