Cloud Uploads

You can upload large attachments quickly directly to Discord's Google Cloud storage bucket, using the endpoints below to generate upload URLs, and sending each generated URL a PUT request with the intended attachment as the body.

This allows you to upload up a file up to 500 MiB directly to Google Cloud. Note that file size limits will still apply when sending the attachment in a message.

An example implementation in Python pseudocode would be:

import requests
import os
url = "https://discord.com/api/v10/channels/<channel_id>/attachments"
headers = {
"Authorization": "Bot <bot_token>"
}
filename = "cat.png"
size = os.stat(filename).st_size
json = {
"files": [{
"file_size": size,
"filename": filename
}]
}
r = requests.post(url, headers=headers, json=json)
r.raise_for_status()
upload = r.json()['attachments'][0]
with open(filename, "r") as f:
data = f.read()
r = requests.put(upload['upload_url'], data=data)
r.raise_for_status()
upload_filename = upload['upload_filename']

Now, instead of sending the attachment again in a form body in the request, you can just send the upload_filename! For example:

{
"content": "look at my cute cat!",
"attachments": [
{
"id": "0",
"filename": "cat.png",
"uploaded_filename": "6a08e58a-265f-485a-8c85-5cd4df0edde0/cat.png"
}
]
}

Upload Attachment Object

Upload Attachment Structure
FieldTypeDescription
id??snowflakeThe ID of the attachment to reference in the response
filenamestringThe name of the file being uploaded (max 1024 characters)
file_sizeintegerThe size of the file being uploaded in bytes
is_clip? 1 2booleanWhether the file being uploaded is a clipped recording of a stream
original_content_type?stringThe attachment's original media type

1 When uploading a clip, an increased default file size limit of 100 MiB applies.

2 Only applicable within Create Message Attachments endpoint.

Cloud Attachment Object

Cloud Attachment Structure
FieldTypeDescription
id?snowflakeThe ID of the attachment upload, if provided in the request
upload_urlstringThe URL to upload the file to
upload_filenamestringThe name of the uploaded file

Endpoints

Create Message Attachments

POST/channels/{channel.id}/attachments

Creates attachment URLs to upload the intended attachments directly to Discord's GCP storage bucket. Returns an array of cloud attachment objects. Requires the same permissions as uploading an attachment inline with a message. See above for more information.

JSON Params
FieldTypeDescription
filesarray[upload attachment object]The target files to create a URL for, containing the name and size (1-10)
Example Response
{
"attachments": [
{
"id": "23",
"upload_url": "https://discord-attachments-uploads-prd.storage.googleapis.com/87e49c99-43f8-4a33-baad-5a834c94424c/cat.png?upload_id=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"upload_filename": "87e49c99-43f8-4a33-baad-5a834c94424c/cat.png"
}
]
}

Create Guild Product Attachments

POST/guilds/{channel.id}/products/attachments

Creates attachment URLs to upload the intended attachments directly to Discord's GCP storage bucket. Returns an array of cloud attachment objects. See above for more information.

JSON Params
FieldTypeDescription
filesarray[upload attachment object]The target files to create a URL for, containing the name and size (1-10)

Create Gravity Attachments

POST/users/@me/gravity-attachments

Creates attachment URLs to upload the intended attachments directly to Discord's GCP storage bucket. Returns an array of cloud attachment objects. See above for more information.

JSON Params
FieldTypeDescription
filesarray[upload attachment object]The target files to create a URL for, containing the name and size (1-10)

Deletes an attachment from Discord's GCP storage bucket. Returns a 204 empty response on success.

This endpoint should be used to delete an uploaded attachment that was not used. See above for more information.

Refresh Attachment URLs

POST/attachments/refresh-urls

Refreshes the URLs of attachments that were uploaded to Discord's CDN. The provided URLs do not have to be valid or signed. Existing query string parameters are preserved.

JSON Params
FieldTypeDescription
attachment_urlsarray[string]The URLs of the attachments to refresh (1-50)
Response Body
FieldTypeDescription
refreshed_urlsarray[refreshed attachment object]The refreshed URLs
Refreshed Attachment Structure
FieldTypeDescription
originalstringThe provided URL
refreshedstringThe refreshed URL
Example Response
{
"refreshed_urls": [
{
"original": "https://cdn.discordapp.com/attachments/1012345678900020080/1234567891233211234/my_image.png?ex=65d903de&is=65c68ede&hm=2481f30dd67f503f54d020ae3b5533b9987fae4e55f2b4e3926e08a3fa3ee24f&",
"refreshed": "https://cdn.discordapp.com/attachments/1012345678900020080/1234567891233211234/my_image.png?ex=66143372&is=6601be72&hm=5a90a0ac363d9de3619044102ffe963041517f0e2f78baecabfc2f544a14eace&"
}
]
}