Upload file su Cloudinary con resource_type: raw
Come caricare PDF, Word, Excel e altri file binari generici su Cloudinary usando un upload preset
unsigned e resource_type=raw โ interamente client-side, senza backend dedicato.
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.
Il problema
Cloudinary รจ ottimo per immagini e video, ma il tipo image di default rifiuta
file binari generici come PDF o documenti Office. Per caricarli serve dichiarare esplicitamente
resource_type=raw nell'URL dell'endpoint di upload.
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 con FormData e fetch
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;
}
Quando usarlo: chat con allegati, sistemi documentali interni, qualunque upload PWA senza backend dedicato โ Cloudinary gestisce CDN, storage e URL pubblici automaticamente.
When to use it: chat attachments, internal document systems, any PWA upload without a dedicated backend โ Cloudinary handles CDN, storage and public URLs automatically.
Configurare il preset unsigned
Su Cloudinary, un upload preset unsigned permette upload diretti dal client senza esporre
la API secret. Nel pannello Cloudinary: Settings โ Upload โ Add upload preset, imposta
Signing Mode: Unsigned e, punto critico, Resource type: Auto (non Image) โ
altrimenti l'upload di un PDF restituisce un errore 400.
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.
Attenzione: un upload preset unsigned รจ pubblico โ chiunque conosca il nome del preset puรฒ caricare file sul tuo account Cloudinary. Per uso pubblico imposta limiti di formato e dimensione nel preset, o passa a upload firmati lato server.
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.
Articolo correlato
Invio documenti in una chat Firebase + Cloudinary โ caso reale completo
Related article
Sending documents in a Firebase + Cloudinary chat โ full real-world case
โ