使用 traffic react box 的 solidity drive app

solidity drive app using the traffic react box

我正在使用 traffic react box 制作 solidity drive 应用程序。

将文件拖到浏览器将文件上传到ipfs,并尝试通过调用已部署的智能联系人保存返回的哈希值。

解密文件时,返回错误'POST http://localhost:5001/api/v0/add?stream-channels=true 403 (Forbidden)'。

我需要有关如何修复它的帮助。

// 这是我的 onDrop 事件代码

  onDrop = async (file) => {
try {
  const {contract, accounts} = this.state;
  const stream = fileReaderPullStream(file);
  const result = await ipfs.add(stream);
  const timestamp = Math.round(+new Date() / 1000);
  const type = file.name.substr(file.name.lastIndexOf(".")+1);
  let uploaded = await contract.methods.add(result[0].hash, file.name, type, timestamp).send({from: accounts[0], gas: 300000})
  console.log(uploaded);
  this.getFiles();
} catch (error) {
  console.log(error);
}

};

这是一个 CORS 问题。 IPFS HTTP API 不能像这样直接从浏览器访问,您需要将它放在诸如配置为正确处理 CORS 的 NGINX 服务器之类的东西后面,以便它能够正常处理基于浏览器的请求。

编辑:

此外,如果您不想使用 NGINX,您可以直接更改 ipfs 节点配置以覆盖您可以访问的域列表。有关详细信息,请参阅 here