简体   繁体   English

如何使用 ipfs.addAll() 获取文件路径或 upload_id

[英]How to get file path or upload_id with ipfs.addAll()

I have progress UI which gets files path and updates progress by file upload_id.我有进度 UI,它通过文件 upload_id 获取文件路径并更新进度。 But in ipfs.addAll function is not returning id or something to show correctly progress.但是在 ipfs.addAll function 中没有返回 id 或显示正确进度的东西。 I mapped files to progress id it repeats every time not working as expected.我将文件映射到进度 id,它每次都没有按预期工作时重复。 How I can fix it?我该如何解决?

for await (const result of ipfs.addAll(fileContent, {
   progress: (progress) => {
     map(files, (item) => {
      dispatch(
       uploadActions.uploadChangeProgress({
        progress,
        id: item.upload_id,
      })
    )
  })
},}))

Looking in the js-ipfs docs for addAll , it mentions there's a second parameter to the progress callback.查看 addAll 的js- addAll文档,它提到progress回调有第二个参数。

a function that will be called with the number of bytes added as a file is added to ipfs and the path of the file being added一个 function 将被调用,并将文件添加到 ipfs 时添加的字节数以及添加的文件的路径

So add that as an argument to your callback to differentiate the files:因此,将其作为参数添加到您的回调中以区分文件:

for await (const result of ipfs.addAll(fileContent, {
   progress: (progress, filePath) => {
      dispatch(
       uploadActions.uploadChangeProgress({
        progress,
        id: filePath, // (unless this needs to be the actual IPFS file ID?)
      })
    )
  })
},}))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM