

# Uploading media files to send with WhatsApp
<a name="managing-media-files-s3"></a>

When you send or receive a media file, it has to be stored in an Amazon S3 bucket and uploaded or retrieved from WhatsApp. The Amazon S3 bucket must be in the same AWS account and AWS Region as your WhatsApp Business Account (WABA). These directions show how to create an Amazon S3 bucket, upload a file, and build the URL to the file. For more information on Amazon S3 commands, see [Use high-level (s3) commands with the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-services-s3-commands.html). For more information on configuring the AWS CLI, see [Configure the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) in the *[AWS Command Line Interface User Guide](https://docs.aws.amazon.com/cli/latest/userguide/)*, and [Creating a bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html), and [Uploading objects](https://docs.aws.amazon.com//AmazonS3/latest/userguide/upload-objects.html) in the *[Amazon S3 User Guide](https://docs.aws.amazon.com/AmazonS3/latest/userguide/)*. 

**Note**  
WhatsApp stores media files for 30 days before deleting them, see [Upload Media](https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#upload-media) in the *WhatsApp Business Platform Cloud API Reference*.

You can also create a [presigned URL](https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html) to the media file. With a presigned URL, you can grant time-limited access to objects and upload them without requiring another party to have AWS security credentials or permissions. 

1. To create an Amazon S3 bucket, use the [create-bucket](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/create-bucket.html) AWS CLI command. At the command line, enter the following command:

   ```
   aws s3api create-bucket --region 'us-east-1' --bucket BucketName
   ```

   In the preceding command:
   + Replace *us-east-1* with the AWS Region that your WABA is in.
   + Replace *BucketName* with the name of the new bucket.

1. To copy a file to the Amazon S3 bucket, use the [cp](https://docs.aws.amazon.com/cli/latest/userguide/cli-services-s3-commands.html#using-s3-commands-managing-objects-copy) AWS CLI command. At the command line, enter the following command:

   ```
   aws s3 cp SourceFilePathAndName s3://BucketName/FileName 
   ```

   In the preceding command:
   + Replace *SourceFilePathAndName* with the file path and name of the file to copy.
   + Replace *BucketName* with the name of the bucket.
   + Replace *FileName* with the name to use for the file.

   The url to use when sending is:

   ```
   s3://BucketName/FileName
   ```

   To create a [presigned URL](https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html), replace the *user input placeholders* with your own information.

   ```
   aws s3 presign s3://amzn-s3-demo-bucket1/mydoc.txt --expires-in 604800 --region af-south-1 --endpoint-url https://s3.af-south-1.amazonaws.com
   ```

   The returned URL will be: `https://amzn-s3-demo-bucket1.s3.af-south-1.amazonaws.com/mydoc.txt?{Headers}`

1. Upload the media file to WhatsApp using the [post-whatsapp-message-media](https://docs.aws.amazon.com/cli/latest/reference/socialmessaging/post-whatsapp-message-media.html) command. On successful completion, the command will return the *\$1MEDIA\$1ID\$1*, which is required for sending the media message.

   ```
   aws socialmessaging post-whatsapp-message-media --origination-phone-number-id {ORIGINATION_PHONE_NUMBER_ID}  --source-s3-file bucketName={BUCKET},key={MEDIA_FILE}
   ```

   In the preceding command, do the following:
   + Replace *\$1ORIGINATION\$1PHONE\$1NUMBER\$1ID\$1* with your phone number's ID.
   + Replace *\$1BUCKET\$1* with the name of the Amazon S3 bucket.
   + Replace *\$1MEDIA\$1FILE\$1* with the name of the media file. 

   You can also upload using a [presign url](#managing-media-files-s3.title) by using `--source-s3-presigned-url` instead of `--source-s3-file`. You must add `Content-Type` in the `headers` field. If you use both then an `InvalidParameterException` is returned.

   ```
   --source-s3-presigned-url headers={"Name":"Value"},url=https://BUCKET.s3.REGION/MEDIA_FILE
   ```

1. On successful completion the *MEDIA\$1ID* is returned. The *MEDIA\$1ID* is used to reference the media file when [sending a media message](send-message-media.md).

# Supported media file types and sizes in WhatsApp
<a name="supported-media-types"></a>

When sending or receiving a media message, the file type must be supported and under the maximum file size. For more information, see [Supported Media Types](https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#supported-media-types) in the *WhatsApp Business Platform Cloud API Reference*.

## Media file types
<a name="reference_body"></a>


**Audio formats**  

| Audio Type | Extension | MIME Type  | Max Size | 
| --- | --- | --- | --- | 
| AAC | .aac | audio/aac | 16 MB | 
| AMR | .amr | audio/amr | 16 MB | 
| MP3 | .mp3 | audio/mpeg | 16 MB | 
| MP4 Audio | .m4a | audio/mp4 | 16 MB | 
| OGG Audio | .ogg | audio/ogg | 16 MB | 


**Document formats**  

| Document Type | Extension | MIME Type  | Max Size | 
| --- | --- | --- | --- | 
| Text | .text | text/plain | 100 MB | 
| Microsoft Excel | .xls, .xlsx | application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | 100 MB | 
| Microsoft Word | .doc, .docx | application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document | 100 MB | 
| Microsoft PowerPoint | .ppt, .pptx | application/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.presentation | 100 MB | 
| PDF | .pdf | application/pdf | 100 MB | 


**Image formats**  

| Image Type | Extension | MIME Type  | Max Size | 
| --- | --- | --- | --- | 
| JPEG | .jpeg | image/jpeg | 5 MB | 
| PNG | .png | image/png | 5 MB | 


**Sticker formats**  

| Sticker Type | Extension | MIME Type  | Max Size | 
| --- | --- | --- | --- | 
| Animated sticker | .webp | image/webp | 500 KB | 
| Static sticker | .webp | image/webp | 100 KB | 


**Video formats**  

| Video Type | Extension | MIME Type  | Max Size | 
| --- | --- | --- | --- | 
| 3GPP | .3gp | video/3gp | 16 MB | 
| MP4 Video | .mp4 | video/mp4 | 16 MB | 