我想在ipfs上发布文件,但它显示了一个错误。
这是我的密码。
const ipfsClient = require('ipfs-http-client');
const ipfs = ipfsClient({host: 'ipfs.infura.io', port: 5001, protocol:
'https'});
function App() {
const [buffer, setBuffer] = useState();
const handleChange = (event) => {
event.preventDefault();
const file = event.target.files[0];
const reader = new window.FileReader();
reader.readAsArrayBuffer(file);
reader.onloadend = () =>{
setBuffer(reader.result);
}
}
const handleSubmit = async(event) => {
event.preventDefault();
console.log('submitting...')
await ipfs.add({buffer}, (error, result) => {
console.log('ipfs results');
if(error){
console.error(error);
return;
}
});
}我在浏览器里看到了这个错误..。
TypeError: ipfsClient不是函数
发布于 2021-11-11 04:44:52
应该是一些彻底的改变。您所拥有的示例的副本很可能是旧版本。如果您访问最新的自述文件,新版本应该由以下内容启动:
import { create } from 'ipfs-http-client'
const client = create()
const client = create(new URL('http://127.0.0.1:5002'))
const { cid } = await client.add('Hello world!')您可以通过指定版本no @ (即npm install ipfs-http-client@42.0.0 )来回滚以使用旧版本。而不是总是使用最新版本的npm install ipfs-http-client (53.X现在)。
还可以在“package.json”文件中查看已安装的版本,查看正在使用的版本,并使用所需的版本进行编辑、删除node_modules文件夹并重新运行npm install。但是这需要保存,这需要一个参数-s,所以运行的是npm install -s ipfs-http-client。
第42版的示例代码应该是您使用的“https://github.com/ipfs/js-ipfs/tree/v42.0.0'”。
Version 53(或官方1.0版本)告诉您,如果您访问官方的github站点,就会发生重大变化;在这里,需要一个create(),而不能直接使用。
发布于 2021-11-11 04:27:20
我对ipfs并不熟悉,但我检查了官方文档,他们做了如下第一行:
const { CID } = require('ipfs-http-client')这些括号是必不可少的。
https://stackoverflow.com/questions/69897780
复制相似问题