Back to blog

How Do I Retrieve Files From IPFS?
IPFS has become the default choice for offchain storage when building crypto and blockchain applications. Its ability to run as a distributed network and its content addressability has made it versatile and portable. Applications using IPFS generally need to be able to do two things:
- Upload / pin files to IPFS
- Retrieved pinned files from IPFS
Just as there are multiple ways you can upload files to IPFS, there are also several ways you can retrieve them. In this post, we’ll cover the primary methods people use today, their strengths and weaknesses, and what you should use in your blockchain applications.
P2P (Peer-to-Peer)
Perhaps the most decentralized method of retrieving content on IPFS is through an IPFS node. When you run an IPFS node on your computer or a server, you can request a file by its CID and save it to disk, and if you’re using the Kubo CLI, then it might look something like this:
# Starts up IPFS Node
ipfs daemon
# Retrieve CID and save as pinnie.png
ipfs get bafkreih5aznjvttude6c3wbvqeebb6rlx5wkbzyppv7garjiubll2ceym4 -o pinnie.png
Through this approach, your IPFS node is making a request to the IPFS network looking for that CID and making a peer-to-peer transfer between your node and the IPFS node that has the content. While the P2P method of retrieving files can be improved through replicating the pins on multiple IPFS nodes, it is still the slowest method out there.
Public IPFS Gateways
When IPFS was a relatively new protocol, the idea of being able to retrieve content both from the peer-to-peer layer and the HTTP layer was a foreign concept for developers. Many thought they have to have an IPFS node running themselves for retrieval and this made it unlikely that developers would use IPFS. Public Gateways were a way to prove that retrieval over HTTP was possible.
However, Public Gateways were never designed for production use. They were built with rate limits and lacked performance. Unfortunately, many people in the early days misunderstood this and used Public Gateways as production solutions and were frustrated by the results. This is a big reason why Pinata was the first pinning service to launch Dedicated IPFS Gateways.
Dedicated IPFS Gateways
For those who need production grade performance - or just want a fast and reliable gateway for their own needs - Dedicated IPFS Gateways are the way to go. Similar to Public Gateways, these specialized Gateways provide an HTTP bridge to IPFS, but without the rate limits and with a lot more speed. Pinata’s Dedicated Gateways also include unique features such as a built in CDN, Image Optimizations, even Access Controls. Since these gateways are unique and account specific, you get the guarantee you can control what comes through. Here’s an example of a 40MB image that is being resized to 1080px with a blazing fast cached response:
https://dweb.mypinata.cloud/ipfs/QmTwDNr6LyRzW8H3XorFDArfKEH3GRV1SkF6bAEBF3P4GJ/1.jpg?img-width=1080
Don’t take our word for it, try it out for yourself today! Dedicated Gateways are available on Pinata’s Free plan, so sign up today and experience the best way to retrieve content from IPFS.
Wrapping Up
Of course, choosing your approach to retrieving files from IPFS will greatly depend on your use case.
- P2P can be useful if you’re trying to build a more raw and decentralized experience.
- Public Gateways can come in handy if you just want to use it for a quick test.
- Dedicated Gateways are ideal if you need speed, security, and reliability for your blockchain or crypto application.
Choose wisely, and of course check out how easy it is to use Pinata!
Happy Pinning! :)