# Sending a photo, video and other media

## Send photo

If you want to send photo as message, you can use **Photo class** and pass it as content to `answer.send` or `MessageSend`

#### Photo class take arguments:

<table><thead><tr><th width="150" data-type="number">Argument</th><th>Description</th><th>Required</th></tr></thead><tbody><tr><td>1</td><td>Type how you want to upload the photo. Pass 'path' if you want to upload local file, or pass 'url' if you want to upload file by url</td><td><strong>Required</strong></td></tr><tr><td>2</td><td>Content. Pass path to the file if you passed 'path' as 1st argument, or pass url if you passed 'url' as 1st argument</td><td><strong>Required</strong></td></tr><tr><td>3</td><td><a href="https://core.telegram.org/bots/api#sendphoto">Options</a></td><td>Optional</td></tr><tr><td>4</td><td>Cache. Pass <code>false</code> to disable the cache</td><td>Optional</td></tr></tbody></table>

{% code title="app.controller.ts" %}

```typescript
import { OnCommand, Controller, MessageSend, Photo } from 'nestgram';
import { AppService } from './app.service';
import * as path from 'path';

@Controller()
export class AppController {
  constructor(private readonly appService?: AppService) {}

  @OnCommand('start')
  async start(): Promise<MessageSend> {
    return new MessageSend(new Photo('path', path.resolve(__dirname, 'image.jpg')));
  }
}
```

{% endcode %}

## Send other media

You can also use other classes to send various media files. For example, use another class instead of the `Photo class`:

* Photo
* Video
* Audio
* Document
* Animation
* Voice
* VideoNote

## Set thumb

You can set the thumb for some media files. Just use the `.setThumb` method on the **media class**

{% hint style="info" %}
.setThumb method takes argument: new instance of the Thumb class
{% endhint %}

{% code title="app.controller.ts" %}

```typescript
import { OnCommand, Controller, MessageSend, Audio, Thumb } from 'nestgram';
import { AppService } from './app.service';
import * as path from 'path';

@Controller()
export class AppController {
  constructor(private readonly appService?: AppService) {}

  @OnCommand('start')
  async start(): Promise<MessageSend> {
    return new MessageSend(
      new Audio('path', path.resolve(__dirname, 'audio.mp3'))
        .setThumb(new Thumb('path', path.resolve(__dirname, 'thumb.jpg')))
    );
  }
}
```

{% endcode %}

## Set caption

To set caption, use `.setCaption` **media class** method

{% hint style="info" %}
.setCaption method takes argument: caption you want to set (*string*)
{% endhint %}

{% code title="app.controller.ts" %}

```typescript
import { OnCommand, Controller, MessageSend, Photo } from 'nestgram';
import { AppService } from './app.service';
import * as path from 'path';

@Controller()
export class AppController {
  constructor(private readonly appService?: AppService) {}

  @OnCommand('start')
  async start(): Promise<MessageSend> {
    return new MessageSend(
      new Photo('path', path.resolve(__dirname, 'photo.jpeg'))
        .setCaption('Photo caption'),
    );
  }
}
```

{% endcode %}

## Media caches

When you upload a new media file, its ID is stored in the `nestgram/media.json` file so that when you resubmit this media file, you don't upload it again

{% hint style="info" %}
If you want to disable cache for the same file, pass `false` as 4th argument to the **media class**
{% endhint %}
