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
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.