首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ipfs文件上传问题

Ipfs文件上传问题
EN

Stack Overflow用户
提问于 2020-05-20 20:23:24
回答 2查看 2.3K关注 0票数 0

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

代码语言:javascript
复制
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添加抛出错误响应

代码语言:javascript
复制
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
   }
 }
}
EN

回答 2

Stack Overflow用户

发布于 2020-05-24 17:31:39

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

试一试如下:

代码语言:javascript
复制
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/

票数 0
EN

Stack Overflow用户

发布于 2020-06-04 10:35:35

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

更改如下: "ipfs-http-client": "^44.0.1"

To: "ipfs-http-client": "^44.1.1",

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61922264

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档