1<!-- 2Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 4SPDX-License-Identifier: curl 5--> 6 7# IPFS 8For an overview about IPFS, visit the [IPFS project site](https://ipfs.tech/). 9 10In IPFS there are two protocols. IPFS and IPNS (their workings are explained in detail [here](https://docs.ipfs.tech/concepts/)). The ideal way to access data on the IPFS network is through those protocols. For example to access the Big Buck Bunny video the ideal way to access it is like: `ipfs://bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi` 11 12## IPFS Gateways 13 14IPFS Gateway acts as a bridge between traditional HTTP clients and IPFS. 15IPFS Gateway specifications of HTTP semantics can be found [here](https://specs.ipfs.tech/http-gateways/). 16 17### Deserialized responses 18 19By default, a gateway acts as a bridge between traditional HTTP clients and IPFS and performs necessary hash verification and deserialization. Through such gateway, users can download files, directories, and other content-addressed data stored with IPFS or IPNS as if they were stored in a traditional web server. 20 21### Verifiable responses 22 23By explicitly requesting [application/vnd.ipld.raw](https://www.iana.org/assignments/media-types/application/vnd.ipld.raw) or [application/vnd.ipld.car](https://www.iana.org/assignments/media-types/application/vnd.ipld.car) responses, by means defined in [Trustless Gateway Specification](https://specs.ipfs.tech/http-gateways/trustless-gateway/), the user is able to fetch raw content-addressed data and [perform hash verification themselves](https://docs.ipfs.tech/reference/http/gateway/#trustless-verifiable-retrieval). 24 25This enables users to use untrusted, public gateways without worrying they might return invalid/malicious bytes. 26 27## IPFS and IPNS protocol handling 28 29There are various ways to access data from the IPFS network. One such way is 30through the concept of public 31"[gateways](https://docs.ipfs.tech/concepts/ipfs-gateway/#overview)". The 32short version is that entities can offer gateway services. An example here 33that is hosted by Protocol Labs (who also makes IPFS) is `dweb.link` and 34`ipfs.io`. Both sites expose gateway functionality. Getting a file through 35`ipfs.io` looks like this: 36`https://ipfs.io/ipfs/bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi` 37 38If you were to be [running your own IPFS 39node](https://docs.ipfs.tech/how-to/command-line-quick-start/) then you, by 40default, also have a [local gateway](https://specs.ipfs.tech/http-gateways/) 41running. In its default configuration the earlier example would then also work 42in this link: 43 44`http://127.0.0.1:8080/ipfs/bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi` 45 46## cURL handling of the IPFS protocols 47 48The IPFS integration in cURL hides this gateway logic for you. Instead of 49providing a full URL to a file on IPFS like this: 50 51``` 52curl http://127.0.0.1:8080/ipfs/bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi 53``` 54 55You can provide it with the IPFS protocol instead: 56``` 57curl ipfs://bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi 58``` 59 60With the IPFS protocol way of asking a file, cURL still needs to know the 61gateway. curl essentially just rewrites the IPFS based URL to a gateway URL. 62 63### IPFS_GATEWAY environment variable 64 65If the `IPFS_GATEWAY` environment variable is found, its value is used as 66gateway. 67 68### Automatic gateway detection 69 70When you provide no additional details to cURL then it: 71 721. First looks for the `IPFS_GATEWAY` environment variable and use that if it 73 is set. 742. Looks for the file: `~/.ipfs/gateway`. If it can find that file then it 75 means that you have a local gateway running and that file contains the URL 76 to your local gateway. 77 78If cURL fails, you are presented with an error message and a link to this page 79to the option most applicable to solving the issue. 80 81### `--ipfs-gateway` argument 82 83You can also provide a `--ipfs-gateway` argument to cURL. This overrules any 84other gateway setting. curl does not fallback to the other options if the 85provided gateway did not work. 86 87## Gateway redirects 88 89A gateway could redirect to another place. For example, `dweb.link` redirects 90[path based](https://docs.ipfs.tech/how-to/address-ipfs-on-web/#path-gateway) 91requests to [subdomain 92based](https://docs.ipfs.tech/how-to/address-ipfs-on-web/#subdomain-gateway) 93ones. A request using: 94 95 curl ipfs://bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi --ipfs-gateway https://dweb.link 96 97Which would be translated to: 98 99 https://dweb.link/ipfs/bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi 100 101redirects to: 102 103 https://bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi.ipfs.dweb.link 104 105If you trust this behavior from your gateway of choice then passing the `-L` 106option follows the redirect. 107 108## Error messages and hints 109 110Depending on the arguments, cURL could present the user with an error. 111 112### Gateway file and environment variable 113 114cURL tried to look for the file: `~/.ipfs/gateway` but could not find it. It 115also tried to look for the `IPFS_GATEWAY` environment variable but could not 116find that either. This happens when no extra arguments are passed to cURL and 117letting it try to figure it out [automatically](#automatic-gateway-detection). 118 119Any IPFS implementation that has gateway support should expose its URL in 120`~/.ipfs/gateway`. If you are already running a gateway, make sure it exposes 121the file where cURL expects to find it. 122 123Alternatively you could set the `IPFS_GATEWAY` environment variable or pass 124the `--ipfs-gateway` flag to the cURL command. 125 126### Malformed gateway URL 127 128The command executed evaluates in an invalid URL. This could be anywhere in 129the URL, but a likely point is a wrong gateway URL. 130 131Inspect the URL set via the `IPFS_GATEWAY` environment variable or passed with 132the `--ipfs-gateway` flag. Alternatively opt to go for the 133[automatic](#automatic-gateway-detection) gateway detection. 134