I am trying to send files to ipfs using a website in node-js. I am using the ipfs-http-client module. When i try to access the module using require I keep getting this error :
- Module not found: Can't resolve 'ipfs-http-client' in 'D:\Pro\src\components' in the command prompt.
This the error message in the website :
- Failed to compile ./src/components/App.js Module not found: Can't resolve 'ipfs-http-client' in 'D:\Pro\src\components' This error occurred during the build time and cannot be dismissed.
I installed the module using the command specified in the official docs - "npm install --save ipfs-http-client" . I can see the module in my dependencies but still getting this error. I am a complete newbie to all this. A little help would be much appreciated. Thanks in advance.
This is how I am accessing the module :
***import React, { Component } from 'react';
import logo from '../logo.png';
import './App.css';
const ipfsClient = require('ipfs-http-client');
const projectId = '*****';
const projectSecret = '***';
const auth =
'Basic ' + Buffer.from(projectId + ':' + projectSecret).toString('base64');
const ipfs = ipfsClient.create({
host: 'ipfs.infura.io',
port: 5001,
protocol: 'https',
headers: {
authorization: auth,
},
});
class App extends Component {
constructor(props) {
super(props);
this.state={
buffer: null
};
}
captureFile=(event) => {
event.preventDefault()
const file = event.target.files[0]
const reader = new window.FileReader()
reader.readAsArrayBuffer(file)
reader.onloadend=() => {
this.setState({buffer: Buffer(reader.result) })
}
console.log(event.target.files)
}
onSubmit = (event) => {
event.preventDefault()
console.log("Submitting the form...")
ipfs.add(this.state.buffer, (error,result) => {
console.log('Ipfs result', result)
if(error){
console.error(error)
return
}
})
}***