i am trying to upload a file to the ipfs server,but i am not able to see any output on my console.
i am not getting any error also.
Code:
Declaring ipfs Cient:-
import { create } from 'ipfs-http-client'
const ipfs=create({host:'ipfs.infura.io',port:5001,protocol:'https',apiPath: '/ipfs/api/v0'});
Creating the file buffer:
const captureFile = event => {
event.preventDefault();
const file=event.target.files[0];
const reader= new window.FileReader();
reader.readAsArrayBuffer(file);
reader.onload=()=>{
setBuffer(Buffer.from(reader.result));
setName(file.name)
setType(file.type);
}
Uploading the file to ipfs:
const uploadFile = async description => {
console.log("submitting the file to IPFS with description: ",description)
await ipfs.add(buffer, (error,result)=>{
console.log("Ipfs result is :",result);
})