JCC Express

Packages

Cloudinary

Introduction

JCC Express MVC includes a Cloudinary integration for uploading images and media from HTTP requests. The service is opt-in — nothing is registered until you publish the component and configure your credentials.

Primary surfaces:

  • req.storeToCloudinary(fileName, option?, returnUrl?) — upload from multipart form fields
  • FormRequest.storeToCloudinary(...) — same API on form request subclasses
  • app.resolve("Cloudinary") — direct access to the Cloudinary client for manual uploads, URL generation, etc.

Installation

Run the publish command from your project root:

Bash
bun artisanNode publish Cloudinary

The command is idempotent — safe to run repeatedly. It:

  1. Creates app/Config/cloudinary.ts (skipped if it already exists; pass force=true to overwrite).
  2. Wires cloudinary into app/Config/index.ts.
  3. Wires CloudinaryServiceProvider into bootstrap/providers.ts.
Bash
# Overwrite existing config
bun artisanNode publish Cloudinary force=true

# List available publishables
bun artisanNode publish

After publishing, add your Cloudinary credentials to .env:

env
CLOUDINARY_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_SECRET=your_api_secret

Restart your dev server (bun run dev) so the provider picks up the new config.


Uploading from requests

Once published and configured, upload a file field directly to Cloudinary:

TypeScript
Route.post("/upload", async (req) => {
  const url = await req.storeToCloudinary("image");
  return { url };
});

See Request for the full API (returnUrl, multiple files, upload options, and FormRequest usage).


Direct client usage

Resolve the Cloudinary client from the container:

TypeScript
const cloudinary = app.resolve<any>("Cloudinary");

const result = await cloudinary.upload("/path/to/file.jpg", {
  folder: "avatars",
});

const imgUrl = cloudinary.url(result.public_id, { width: 200, crop: "fill" });
const imgTag = cloudinary.image(result.public_id, { alt: "Avatar" });

Summary

  • Run bun artisanNode publish Cloudinary to enable the integration.
  • Set CLOUDINARY_NAME, CLOUDINARY_API_KEY, and CLOUDINARY_SECRET in .env.
  • Use req.storeToCloudinary() for request uploads or app.resolve("Cloudinary") for direct access.