Cloudinary is a cloud media management service (SaaS) that handles uploading, storage, on-the-fly transformations (resize/crop/format/quality), optimization and CDN delivery for images and videos. It provides REST APIs and SDKs for frontends and backends so you can offload media work to a specialist service instead of your own servers.
Start learning how to build softwares
From your React project root:
npm install @cloudinary/react @cloudinary/url-gen
# or
yarn add @cloudinary/react @cloudinary/url-gen (These are Cloudinary’s current frontend SDKs for React + URL generation/transformations.)
Create a Cloudinary instance and render an image with AdvancedImage.
Example CloudinaryProvider usage (simple):
// src/cloudinary.js
import { Cloudinary } from "@cloudinary/url-gen";
export const cld = new Cloudinary({
cloud: { cloudName: process.env.REACT_APP_CLOUDINARY_CLOUD_NAME }
}); Example component showing an image and simple transform:
// src/components/Photo.jsx
import React from "react";
import { AdvancedImage } from "@cloudinary/react";
import { cld } from "../cloudinary";
import { fill } from "@cloudinary/url-gen/actions/resize";
export default function Photo({ publicId }) {
// build image with transformations
const myImage = cld.image(publicId).resize(fill().width(400).height(300));
return <AdvancedImage cldImg={myImage} alt="Uploaded asset" />;
} This uses Cloudinary URL-Gen to create a URL with transforms, and AdvancedImage renders it with lazy loading and other optimizations.
cloud_name and an unsigned upload preset (unless you use server-signed widget).Minimal example:
// UploadWidget.jsx
import React, { useEffect } from "react";
export default function UploadWidget({ onUpload }) {
useEffect(() => {
// ensure widget script loaded (you can include script in index.html or dynamically)
const widget = window.cloudinary.createUploadWidget(
{
cloudName: process.env.REACT_APP_CLOUDINARY_CLOUD_NAME,
uploadPreset: "your_unsigned_preset"
},
(error, result) => {
if (!error && result && result.event === "success") {
onUpload(result.info); // result.info has public_id, secure_url, etc.
}
}
);
// attach to a button
document.getElementById("uploadBtn").addEventListener("click", () => widget.open(), false);
}, [onUpload]);
return <button id="uploadBtn">Upload image</button>;
} Pros: very easy, great UX.
Cons: limited customization unless you roll your own; unsigned presets may be abused if public.
async function uploadFile(file) {
const url = `https://api.cloudinary.com/v1_1/${CLOUD_NAME}/upload`;
const formData = new FormData();
formData.append("file", file);
formData.append("upload_preset", "your_unsigned_preset");
const res = await fetch(url, { method: "POST", body: formData });
const data = await res.json();
return data; // contains public_id, secure_url...
} Security note: unsigned uploads are easier but the preset controls allowed parameters — still less safe for sensitive apps.
Why signed? Signed uploads require a signature from your server (which has the API secret), preventing malicious clients from arbitrarily setting upload parameters, folders, or using privileges you don’t intend to expose.
Flow: client asks your server for a timestamp + signature (and maybe api_key); server generates signature using API secret; client calls Cloudinary upload endpoint with file + signature + timestamp.
// server/signature.js
require("dotenv").config();
const express = require("express");
const crypto = require("crypto");
const app = express();
app.get("/signature", (req, res) => {
const timestamp = Math.round(Date.now() / 1000);
// include any params you want to sign (e.g., folder, eager, public_id)
const paramsToSign = `timestamp=${timestamp}${process.env.CLOUDINARY_API_SECRET}`;
const signature = crypto.createHash("sha1").update(paramsToSign).digest("hex");
res.json({
timestamp,
signature,
api_key: process.env.CLOUDINARY_API_KEY // client needs api_key too
});
});
app.listen(3001); (Cloudinary has helper methods in backend SDKs that produce the signature for you — prefer the official cloudinaryNode SDK for production. Docs: generating signatures & Node SDK.)
Client: using the signature to upload
async function uploadSigned(file) {
// 1. get signature + timestamp from your server
const sigRes = await fetch("/signature");
const { signature, timestamp, api_key } = await sigRes.json();
// 2. upload to Cloudinary
const formData = new FormData();
formData.append("file", file);
formData.append("api_key", api_key);
formData.append("timestamp", timestamp);
formData.append("signature", signature);
const res = await fetch(`https://api.cloudinary.com/v1_1/${CLOUD_NAME}/upload`, {
method: "POST",
body: formData
});
return await res.json();
} public_id, secure_url, width/height, format, etc. Store public_id or secure_url in your DB for later display. Use public_id with URL-Gen to apply transformations easily.srcset with AdvancedImage behavior). This reduces bandwidth and improves performance.npm i @cloudinary/react @cloudinary/url-gen in your React app.AdvancedImage + url-gen to display images and createUploadWidget or direct upload code for uploads. Cloudinary is a powerful cloud-based media management service that helps developers easily upload, store, optimize, and deliver images and videos in React applications. By integrating Cloudinary with React, you can offload complex image handling tasks—like resizing, transformation, and CDN delivery—to Cloudinary’s infrastructure. Using the React SDK and Upload Widget (or API), developers can quickly implement secure client-side uploads, display optimized media, and ensure high performance across devices while maintaining control over asset management and transformations.
Latest tech news and coding tips.
1. What Is the Golden Ratio? The Golden Ratio, represented by the Greek letter φ (phi), is…
In CSS, combinators define relationships between selectors. Instead of selecting elements individually, combinators allow you to target elements based…
Below is a comprehensive, beginner-friendly, yet deeply detailed guide to Boolean Algebra, complete with definitions, laws,…
Debugging your own code is hard enough — debugging someone else’s code is a whole…
Git is a free, open-source distributed version control system created by Linus Torvalds.It helps developers: Learn how to…
Bubble Sort is one of the simplest sorting algorithms in computer science. Although it’s not…