javascript - ipfs文件上传问题
问题描述
我正在使用 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
}
}
}
解决方案
我发现了一个错误,问题是 ipfs-http-client 版本 (^44.0.1)。当我将其更新到最新版本 (^44.1.1) 时,错误已解决。
改变这个:
"ipfs-http-client": "^44.0.1"
至:
"ipfs-http-client": "^44.1.1",
推荐阅读
- xml - 按标签内的值对 XML 进行排序
- javascript - JavaScript 导入 HTML 文件内容(目标是浏览器)
- python - Python MySQL 无法使用包含 25k 条记录的数据集进行更新
- java - 使用 java 和流 API 寻找给定代码片段的改进
- android - Completable 中的单个 delaySubscription 等效项
- java - 带数组的二项式系数
- word2vec - 保存 word2vec 模型会导致文件混乱
- reactjs - 在 React 虚拟化表上实现过滤器
- vector - 使用 gensim 从词袋向量创建 LDA 模型
- php - Woocommerce 的自定义管理员电子邮件主题