I am trying to upload an image to ipfs
in my svelte app. This is the code where I try to upload the image:
const uploadFile = async (file) => {
const ipfs = await IPFS.create();
const result = await ipfs.add(file);
console.log(result)
}
file
is in ArrayBuffer
format.
However, it returns the error saying:
(8) index.js:54 Uncaught (in promise) TypeError: callback is not a function
at Function../node_modules/peer-info/src/index.js.PeerInfo.create (index.js:54)
at GossipSub._onIncomingStream (index.js:174)
at Upgrader._onStream (upgrader.js:313)
at Mplex.onStream (upgrader.js:235)
You can try adding the file by using ipfs.add in a for loop:
for await (const result of ipfs.add(file)) {
console.log(result);
}
More info here: https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#add