gpt4 book ai didi

javascript - 使用流量 react 盒的 Solidity Drive 应用程序

转载 作者:行者123 更新时间:2023-12-02 22:14:30 25 4
gpt4 key购买 nike

我正在使用流量 react 框制作 Solidity Drive 应用程序。

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

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

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

//这是我的 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 无法直接从这样的浏览器访问,您需要将其放置在 NGINX 服务器之类的东西后面,该服务器配置为正确处理 CORS,以便它能够正确处理基于浏览器的请求。

编辑:

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

关于javascript - 使用流量 react 盒的 Solidity Drive 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59433601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com