# How to know what type of file a CID represents?

**URL:** <https://discuss.ipfs.tech/t/how-to-know-what-type-of-file-a-cid-represents/16007>\
**Category:** Help\
**Created:** [February 20, 2023, 1:43pm UTC](https://discuss.ipfs.tech/t/how-to-know-what-type-of-file-a-cid-represents/16007 "2023-02-20T13:43:19Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![danieln](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/danieln/32/6408_2.png) [@danieln](https://discuss.ipfs.tech/u/danieln)\
**Post date:** [February 20, 2023, 2:09pm UTC](https://discuss.ipfs.tech/t/how-to-know-what-type-of-file-a-cid-represents/16007/2 "2023-02-20T14:09:20Z")

</div>

> [@DeveloperAlly](#):
>
> Q: Is there any way to see what sort of data a CID represents from the CID or bytes data?

I’ll take a stab at answering this with an example.

Let’s say you have the following CID of an [image](https://ipfs.io/ipfs/bafybeibml5uieyxa5tufngvg7fgwbkwvlsuntwbxgtskoqynbt7wlchmfm): `bafybeibml5uieyxa5tufngvg7fgwbkwvlsuntwbxgtskoqynbt7wlchmfm`

If you load the CID in the [CID inspector](https://cid.ipfs.tech/#bafybeibml5uieyxa5tufngvg7fgwbkwvlsuntwbxgtskoqynbt7wlchmfm) you can see the multicodec is `dag-pb` which is a `MerkleDAG protobuf`. This just helps decode the block that this CID points to, but won’t tell you much about the file.

### If the CID doesn’t contain the information, maybe the root block does?

The answer is no. For more information, check out the [UnixFS Data Format](https://github.com/ipfs/specs/blob/main/UNIXFS.md#data-format).

Below is a screenshot from the IPLD explorer for this CID

 ![Screenshot 2023-02-20 at 2.57.35 PM](https://us1.discourse-cdn.com/flex020/uploads/ipfs1/original/2X/0/09897c04ab4f921da3c7b1e4554e99b1908871e5.png)

The root block just has information on whether it’s a file or folder in addition to links to the CIDs of the blocks that contain the images bytes.

### What about looking at the file extension?

That’s a nice idea. The first problem is that it’s only relevant for files that are wrapped in a directory in UnixFS (see for more info [Getting the file names of files I pinned locally - #2 by danieln](https://discuss.ipfs.tech/t/getting-the-file-names-of-files-i-pinned-locally/14655/2)).

The second problem is that it’s not always reliable and not all files have an extension.

### Ok, so how can I find out what kind of file this is?

The most reliable way is to peek at the beginning of the file and decipher [the **file signature** also known as **“magic bytes”**](https://en.wikipedia.org/wiki/List_of_file_signatures).

In fact, this is what Kubo does when you make a gateway request in order to set the **`content-type: image/jpeg`** header when you load the [image](https://ipfs.io/ipfs/bafybeibml5uieyxa5tufngvg7fgwbkwvlsuntwbxgtskoqynbt7wlchmfm).

### Can I see an example?

> <https://github.com/2color/verified-ipfs-retrieval/blob/main/src/components/VerifiedImage.tsx#L45>

This uses [GitHub - LarsKoelpin/magic-bytes: A library for detecting file types.](https://github.com/LarsKoelpin/magic-bytes) to determine the type of the file.

---

_[View the full topic](https://discuss.ipfs.tech/t/how-to-know-what-type-of-file-a-cid-represents/16007)._
