Search code examples
ipfs

Is it possible to send data from IPFS node to web2 server?


Imagine I hosted website on IPFS with contact form on the page. Is there any way to get submitted values (to have them to be pushed to some web2 classic server)? What is the general option for data sharing?


Solution

  • Whether or how this works really depends on how your users consume the website on ipfs. Assuming they use a regular browser and communicate with a public IPFS (e.g. https://ipfs.io/ipfs/QmRQvNf2KugVgH7EpX4WviAvaWeQ3pRLGD4ibXmZTk2tGW or https://bafkreiedi665akdjnucmzn4562yfdgducj3a2at4uryksgvmykfwponjnu.ipfs.dweb.link) or a local gateway, you can use all the methods available in classical web development.

    For example, you can add a simple HTML form,

    <form action="https://domain.example.com/form-processing" method="POST">
    <input ... />
    </form>
    

    that submits the data via regular HTTP. The submission of a plain HTML form works across domain boundaries, here from ipfs.io to domain.example.com.

    Besides the form, you can send and receive data via HTTP using in-browser javascript that sends AJAX requests to your server. This can fail depending on the request method and content type. To enable resource sharing across domain boundaries, consider adding appropriate CORS headers to the server reply, although this might introduce security issues.