首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在将文件上传到IPFS后生成密钥时出错

在将文件上传到IPFS后生成密钥时出错
EN

Ethereum用户
提问于 2019-01-28 09:17:37
回答 1查看 322关注 0票数 0

我得到了一个错误,而生成密钥后,上传文件到IPFS格式。

下面提供的示例代码

代码语言:javascript
复制
var ipfsAPI = require('ipfs-http-client');
const ipfs = ipfsAPI('ipfs.infura.io', '5001', { protocol: 'https' });
var oldpath = files[property].path;
var uploadedFile = fs.readFileSync(oldpath);
const filess = [{
                    path: files[property].name,
                    content: ipfs.types.Buffer.from(uploadedFile)
             }];
 ipfs.add(filess, function (err, files) {

                  if (err || !files) {
                        return reject('upload failed');
                    };
 var obj;
for (i = 0; i < data.length; i++) {
    obj = { "id": i, "hash": data[i], "EID": formFields.EID };
    tt.push(obj);
}
ipfs.dag.put(tt, {}, (err, cid) => {
    console.log(cid.toBaseEncodedString());
    const adr = cid.toBaseEncodedString();
    var dTimeStamp = new Date().getTime();
ipfs.key.gen(dTimeStamp, {
type: 'rsa',
size: 2048
}, (err, key) => {
    if (err != null) {
        console.log(err)
        }

    console.log("ipfs Key: ", key.id + " key name : " + key.name);

    var keyVall = key.id;


ipfs.name.publish(adr, { key: keyVall }, (err, pVal) => {


        console.log("published hash : " + pVal);

        var ipfsHash = pVal.name;


    return resp.json({ status: 'SUCCESS', message: 'user has been created successfully', digitalID: pVal });
});
});
});

});

在生成密钥时,我得到了一个以下错误

代码语言:javascript
复制
"SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at streamToValue (C:\Service\node_modules\ipfs-http-client\src\utils\stream-to-json-value.js:25:18)
    at concat (C:Service\node_modules\ipfs-http-client\src\utils\stream-to-value.js:12:22)
    at ConcatStream.<anonymous> (C:Service\node_modules\concat-stream\index.js:37:43)
    at ConcatStream.emit (events.js:187:15)
    at finishMaybe (C:Service\node_modules\readable-stream\lib\_stream_writable.js:630:14)
    at afterWrite (C:Service\node_modules\readable-stream\lib\_stream_writable.js:492:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)"

任何线索都将不胜感激。

EN

回答 1

Ethereum用户

回答已采纳

发布于 2019-01-28 09:53:43

Infura服务只允许通过其网关提供一小部分IPFS方法,因此您不能通过ipfs.key.gen生成密钥

见恩弗拉文件

我建议运行您自己的IPFS节点,特别是如果您想生成和存储密钥区。

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

https://ethereum.stackexchange.com/questions/66241

复制
相关文章

相似问题

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