【问题标题】:Ipfs file uploading issueipfs文件上传问题
【发布时间】:2020-09-07 08:39:14
【问题描述】:

我正在使用 IPFS 服务进行文件存储。从 Node.js 应用程序中,我可以初始化 IPFS_Node 并使用此节点上传文件。

var ipfs = ipfsClient({
            // the hostname (or ip address) of the endpoint providing the ipfs api
            host: '*****************',
            // the port to connect on
            port: '443',
            // 'api-path': '/api/v0/',
            // the protocol, https for security
            protocol: 'https',
            // provide the jwt within an authorization header
            headers: {
                authorization:
                    'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ**********************'
            }
        });
    for await (const response of ipfs.add(file.buffer)) {
            console.log(response);
            res.json({ response: response, status: 200 });
        }

Ipfs 添加抛出错误响应

HTTPError: Unauthorized

   at Object.errorHandler [as handleError] (C:\Users\Rohail\Documents\GitHub\Artbot_api\node_modules\ipfs-http-client\src\lib\core.js:67:15)        
   at processTicksAndRejections (internal/process/task_queues.js:93:5)
   at Client.fetch (C:\Users\Rohail\Documents\GitHub\Artbot_api\node_modules\ipfs-utils\src\http.js:145:9)
   at Object.add (C:\Users\Rohail\Documents\GitHub\Artbot_api\node_modules\ipfs-http-client\src\add.js:13:17) {
 name: 'HTTPError',
 response: Response {
   size: 0,
   timeout: 0,
   [Symbol(Body internals)]: { body: [PassThrough], disturbed: true, error: null },
   [Symbol(Response internals)]: {
     url: 'https://api.ipfs.temporal.cloud/api/v0/add?stream-channels=true&progress=false',
     status: 401,
     statusText: 'Unauthorized',
     headers: [Headers],
     counter: 0
   }
 }
}

【问题讨论】:

    标签: javascript node.js file fs ipfs


    【解决方案1】:

    我发现了一个错误,问题是 ipfs-http-client 版本 (^44.0.1)。 当我将其更新到最新版本 (^44.1.1) 时,错误已解决。

    改变这个: "ipfs-http-client": "^44.0.1"

    收件人: "ipfs-http-client": "^44.1.1",

    【讨论】:

      【解决方案2】:

      不确定这是否有帮助,但如果您使用的是最新版本的ipfs-http-client,那么ipfs.add 现在会返回AsyncIterable<Object> 而不是Promise

      尝试类似:

      const all = require('it-all')
      const data = await all(ipfs.add(file))
      console.log(data)
      

      欲了解更多信息,请参阅:https://blog.ipfs.io/2020-02-01-async-await-refactor/

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-02
      • 2010-10-17
      相关资源
      最近更新 更多