# Downloading files

Downloading files is fairly simple using the `downloadMedia` method.

First, you'll need to get the media somehow. the easiest way would be to either use getMessages

```typescript
const result = await client.getMessages("me", {
    ids: 87581 // the id of the message you want to download
});
const media = result[0].media;
if (media) {
    const buffer = await client.downloadMedia(media, {
        workers: 1,
    });
    console.log("result is", buffer);
}
```

You could also get the from events. See the Updates doc on how to do that.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://painor.gitbook.io/gramjs/getting-started/available-methods/downloading-files.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
