IPFS HTTP Gateways
web3.storage uses the InterPlanetary File System (IPFS) (opens in a new tab) as a key part of its storage and retrieval infrastructure.
The IPFS network is a peer-to-peer network of computers that share resources to efficiently provide content to anyone that requests it. Computers that join the IPFS network supply blocks of data using a hash-based Content Identifiers (CIDs).
To make IPFS data accessible outside of the peer-to-peer network, special IPFS nodes called "gateways" (opens in a new tab) act as bridges between the HTTP protocol that all web browsers understand and IPFS-native protocols.
As more browsers like Brave (opens in a new tab) and Opera (opens in a new tab) adopt native IPFS support, the need for gateways will naturally lessen over time. Today, you can reach the widest audience by using HTTP gateways in your web applications, but it's a great idea to also surface the original ipfs:// URI for your content, so that IPFS-native browsers can access the content directly through Bitswap.
For more information about fetching content that you uploaded through an IPFS HTTP gateway, see the Retrieve section.
The official IPFS documentation on gateways (opens in a new tab) is helpful for understanding the types of gateways in the IPFS ecosystem and how they're used.
One of the key things to understand for our purposes is the different resolution styles (opens in a new tab) that can be used to fetch content using gateway URLs.
If you check the list of public gateways (opens in a new tab), you'll see that some support "subdomain" style URLs, while others only support path-style URLs. Below is a short refresher on the distinction between the two styles.
A "path style" URL puts the IPFS CID into the path portion of the gateway URL, like this:
If the CID points to a directory listing, you can append the name of a file within the directory to fetch the file:
A "subdomain style" gateway URL puts the CID into the host portion of the URL, as a subdomain of the gateway host, like this:
If the CID points to a directory listing, you can use the path portion of the URL to specify the filename:
This is the preferred style for serving web assets over HTTP gateways, because web browsers provide security isolation on a per-domain basis. Using the subdomain style, every CID gets its own "namespace" for things like cookies and local storage, which isolates things from other web content stored on IPFS.