Back to all questions

What File Formats are Supported by the Cloudinary API?

Alex Khazanovich
APIs
September 20, 2024

Cloudinary supports many file formats, including common image formats like JPEG, PNG, GIF, BMP, WebP, AVIF, and SVG. 

For videos, it supports MP4, WebM, MOV, AVI, and FLV. Audio formats include MP3, OGG, and WAV. Additionally, Cloudinary can handle raw files such as PDFs, ZIP files, DOCX, and PSDs. 

{{cool-component}}

Here’s what this mumbo-jumbo means for you:

Image Formats

Images are probably the most common type of media you'll upload. Cloudinary supports JPEG, PNG, GIF, BMP, and TIFF.

The f_auto feature in the Cloudinary API allows you to automatically serve the most optimal format for the user's browser. So, for instance, if someone’s browser supports WebP, Cloudinary will automatically serve that version instead of JPEG. It's a neat trick that saves you a lot of time in optimizing images:

Format Description Use Case Compressed Transparency Support
JPEG Standard image format General web usage, high compression Lossy No
PNG High-quality images with transparency Logos, images with transparency Lossless Yes
GIF Supports simple animations Simple animations, low-color images Lossy Yes
WebP Modern web-optimized format Web delivery, better compression Lossy & Lossless Yes
AVIF Newer format with better compression Web delivery, high-quality images Lossy & Lossless Yes
SVG Scalable vector graphics Icons, logos, scalable images Vector Yes
BMP Bitmap image format Older image format Lossless No
TIFF High-quality images, often used in printing Photography, archival storage Lossless Yes

There’s a slight catch with SVGs. You can convert them to other formats, but serving them directly requires a bit of additional work to ensure the file is sanitized for security purposes. 

Video Formats

Now, let's talk about videos. Cloudinary supports all the major formats you'd expect: MP4, WebM, MOV, AVI, and FLV

Format Description Use Case Compressed Streaming Support
MP4 Most common video format Web, mobile, all-purpose video Lossy Yes
WebM Optimized for web Web, faster loading videos Lossy Yes
MOV Apple’s video format High-quality video, editing Lossy Yes
AVI Older video format Legacy systems, editing Lossy No
FLV Flash video Flash content, legacy systems Lossy No

Cloudinary's API lets you convert videos between formats if needed. You can trim, resize, and even overlay text or images on videos—all through the API. 

Audio Formats

Cloudinary supports MP3, OGG, and WAV for audio files. I haven't used Cloudinary for audio as much, but it works well if you need to manage and deliver audio assets.

Format Description Use Case Compressed Streaming Support
MP3 Common audio format Audio for web, mobile Lossy Yes
OGG Open-source format Streaming audio Lossy Yes
WAV High-quality audio Audio editing, lossless sound Lossless No

You can transform these files similarly to images and videos, although the transformations are more limited to basic tasks like trimming.

Raw File Formats

Now, beyond media, Cloudinary handles what they call raw files—essentially anything that’s not an image or video. This includes formats like PDF, ZIP, DOCX, PSD, and more.

For example, you can upload a PDF and either deliver it directly or create a thumbnail preview:

Format Description Use Case File Type
PDF Document format Document storage, download Raw
ZIP Compressed archive Storage and compression Raw
DOCX Microsoft Word documents Document storage Raw
PSD Adobe Photoshop files Image editing and design Raw

For free accounts, some raw formats like ZIP and PDF are blocked from public delivery unless you enable specific settings in your Cloudinary dashboard

Once you enable these, or if you’re on a paid plan, you’re good to go. 

Cloudinary Tutorial: Uploading and Transforming

Let’s say you want to upload an image. Using Cloudinary’s API, the basic format looks like this:

uploader.upload("image.jpg", allowed_formats=['jpg', 'png', 'webp'])

You can restrict uploads to certain formats using the allowed_formats parameter, as shown above. If the user uploads an unsupported file format, Cloudinary will reject it unless you tell it to convert on the fly.

For videos, you can specify the same kind of transformations:

uploader.upload("video.mov", resource_type = "video")

By setting the resource_type as video, Cloudinary will handle the file appropriately, allowing you to later transform or convert it into something like MP4.

{{cool-component}}

File Restrictions and Format Conversions

Cloudinary gives you control over which file formats can be uploaded by using the allowed_formats parameter in the API. For example, if you only want to allow PNG uploads, you can enforce that by configuring the API or an upload preset. 

On top of that, if a user uploads a file in the wrong format, Cloudinary can automatically convert it to the allowed format before completing the upload. 

Here's an example in Python where you restrict uploads to PNG files only:

uploader.upload("image.jpg", allowed_formats=['png'], format='png')

In this case, Cloudinary converts any non-PNG file to PNG before storing it.