← blog
JavaScript Cloudinary Zero backend Upload

Uploading files to Cloudinary with resource_type: raw

How to upload PDFs, Word docs, Excel files and other generic binary files to Cloudinary using an unsigned upload preset and resource_type=raw — fully client-side, no dedicated backend.

The problem

Cloudinary is great for images and video, but the default image type rejects generic binary files like PDFs or Office documents. To upload them you need to explicitly declare resource_type=raw in the upload endpoint URL.

Upload with FormData and fetch

upload.js
async function uploadFileRaw(file) {
  const fd = new FormData();
  fd.append('file', file);
  fd.append('upload_preset', 'NOME_PRESET'); // preset unsigned già configurato

  // resource_type=raw — obbligatorio per file non-immagine/video
  const res = await fetch(
    `https://api.cloudinary.com/v1_1/CLOUD_NAME/raw/upload`,
    { method: 'POST', body: fd }
  );

  const data = await res.json();
  if (!res.ok) throw new Error(data.error?.message || 'Upload fallito');

  return data.secure_url;
}

When to use it: chat attachments, internal document systems, any PWA upload without a dedicated backend — Cloudinary handles CDN, storage and public URLs automatically.

Configuring the unsigned preset

On Cloudinary, an unsigned upload preset allows direct client-side uploads without exposing the API secret. In the Cloudinary dashboard: Settings → Upload → Add upload preset, set Signing Mode: Unsigned and, critically, Resource type: Auto (not Image) — otherwise uploading a PDF returns a 400 error.

Warning: an unsigned upload preset is public — anyone who knows the preset name can upload files to your Cloudinary account. For public-facing use, set format and size limits in the preset, or switch to server-side signed uploads.

Related article
Sending documents in a Firebase + Cloudinary chat — full real-world case

When to use this Cloudinary upload pattern

This snippet shows how to upload binary files (PDF, Word, Excel) to Cloudinary using resource_type=raw and an unsigned upload preset, in vanilla JavaScript with no backend needed.

When to use it

When NOT to use it

Alternatives

Common mistakes

Frequently asked questions about uploading raw files to Cloudinary

Because Cloudinary treats files as images by default; for binary files like PDF, Word, or Excel, you need to explicitly specify resource_type=raw so they're handled and served correctly.

It can be, if carefully configured: limiting maximum size, allowed file types, and, if needed, setting additional restrictions on the Cloudinary side. Since it's public, it doesn't offer the same control as a server-side signed upload.

No, the whole point of this snippet is to avoid a dedicated backend, using Cloudinary's upload endpoint directly from the browser with an unsigned preset.