First Step
For this demonstration, I am going to create a simple HTML page consisting of a form that accepts an image as an input and I am going to use Axios CDN in the frontend to send an HTTP request to the server.
Axios cdn — https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js
Second Step
Create an app.js
file and add click
event listener to the form submit button.
Whenever we click the submit button this event-listener should be triggered and it should create a form-data and send it as a POST
request to our Express server.
Third Step
Now our front-end part is over then we have to set up the server and create the route handlers to handle this request.
And then we have to configure multer to read the image and store it as a buffer, and then directly uploading the buffer onto ipfs by creating an ipfs node. This will return some data in response that has the required CID which will uniquely locate the image in ipfs.
Conclusion
Thus we have taken the image from the frontend, passed it to the backend through axios, configured multer a bit and then we uploaded our image onto ipfs. The content field could be modified to hold any documents or buffer etc.
That’s all guys. Hope you’ve enjoyed my article. See you in the next one.