Quick Answer
ImageKit Nuxt upload is a pattern where your Nuxt server (or Nitro API route) talks to ImageKit with the private key, and the browser only gets back a public CDN URL. Use it whenever admin or user uploads must hit a CDN but the private key must never ship to the client. Client-only SDK uploads are fine only if you generate short-lived auth params on the server first.
Quick Facts
| Item | Details |
|---|---|
| Topic | ImageKit Nuxt upload |
| Category | Nuxt / Vue / Media |
What Is ImageKit Nuxt Upload?
It is not “drop the ImageKit private key in nuxt.config public runtime and call it a day.” That leaks the key in the browser bundle.
In a Nuxt app, ImageKit upload usually means: compress the file in the admin UI, POST multipart to a Nitro route, authenticate the admin (Supabase cookie or Bearer), then call ImageKit’s Node SDK with IMAGEKIT_PRIVATE_KEY. The route returns url + fileId. Your blog cover, OG image, or media library stores that URL — same as you would with Supabase Storage, just a different host.
If you need pure client uploads (progress bars in the browser), keep the private key on the server and expose only GET /api/imagekit/auth that returns token, expire, and signature for the ImageKit JS SDK.
Why It Matters
- Key safety — a leaked private key lets anyone upload (and often delete) under your ImageKit account.
- CDN URLs out of the box — covers and inline images load from
ik.imagekit.iowith transforms, without you running an image proxy. - Clean admin UX — compress → upload → paste URL into the post. No manual FTP, no giant base64 in HTML.
How It Works
Three pieces move on every upload.
flowchart LR AdminUI[Admin UI] --> Nitro[Nitro API route] Nitro --> Auth[Require signed-in admin] Auth --> IK[ImageKit Node SDK] IK --> CDN[ik.imagekit.io URL] CDN --> AdminUI
- Admin UI — picks a file, optionally compresses to WebP, builds
FormData. - Nitro route — checks the user session, validates MIME/size, maps the folder under something like
portfolio/posts/…. - ImageKit — uploads with the private key, returns public
urlandfileIdfor later delete/list.
Step-by-Step Guide
Step 1: Add ImageKit env keys
In .env (and Vercel/host env for production):
IMAGEKIT_URL_ENDPOINT=https://ik.imagekit.io/YOUR_ID/
IMAGEKIT_PUBLIC_KEY=public_xxx
IMAGEKIT_PRIVATE_KEY=private_xxx
Wire private key into runtimeConfig (server-only). Put URL endpoint and public key under runtimeConfig.public if the client needs them for transforms. Done check: after nuxt dev restart, the private key is readable in a server route and not in the client payload.
Step 2: Create a protected upload API route
Add something like server/api/imagekit/upload.post.ts. Require a logged-in admin (Supabase serverSupabaseUser / Bearer). Reject non-images and files over your limit (8MB is a sane ceiling). Upload with @imagekit/nodejs into a fixed root folder, for example portfolio/posts/{subfolder}, so one Media Library view can list everything.
Done check: unauthenticated curl to the route returns 401. Authenticated upload returns JSON with url starting with your ImageKit endpoint.
Step 3: Call the route from the admin uploader
In the shared upload helper, compress first, then:
const form = new FormData()
form.append('file', compressed.blob, compressed.fileName)
form.append('folder', 'blog/cover')
await $fetch('/api/imagekit/upload', {
method: 'POST',
body: form,
headers: { Authorization: `Bearer ${accessToken}` },
})
Save url on the blog post cover / OG / inline figure. Done check: open the returned URL in a private window — image loads without being logged into admin.
Real-World Example
Stack: Nuxt 4 admin + Supabase Auth + ImageKit media library. Goal: blog covers upload from the same admin that edits AEO posts.
Failure mode we hit: env vars were in .env but the dev server was not restarted, so runtimeConfig.imagekitPrivateKey was empty. The API returned ImageKit not configured: missing IMAGEKIT_PRIVATE_KEY even though the dashboard keys looked fine.
Fix: restart Nuxt after any IMAGEKIT_* change, confirm the key is only on the server config, and keep a Media Library list route that walks portfolio/posts so new uploads show up without digging through the ImageKit UI.
Pros & Cons
Advantages
- CDN + transforms without running Sharp on every request yourself.
- Server upload keeps the private key off the network tab.
- Folder tags (
portfolio,admin) make cleanup and audits easier later.
Disadvantages
- Another vendor and bill next to Supabase Storage — you maintain two mental models if you keep both.
- List/delete need ImageKit APIs (
assets.list,files.delete), not just a storage bucket policy. - Client-side progress for huge files needs the signed auth flow, not only the server multipart route.
Best Practices
- Compress before upload (WebP, max dimensions) so you do not burn bandwidth on 5MB phone photos.
- Namespace folders per product area:
portfolio/posts/blog/cover,…/og,…/inline. - Gate every ImageKit route with the same admin auth you use for publish.
- Store
fileIdwhen you can — delete by path alone is awkward in ImageKit. - Keep old Supabase upload code commented nearby if you need a one-day rollback, but do not run both blindly.
Common Mistakes
- Private key in
publicruntimeConfig — it ends up in the client. Fix: onlyruntimeConfig.imagekitPrivateKey(server). - Forgot to restart after .env edit — Nitro still has empty keys. Fix: restart
nuxt dev/ redeploy. - Open upload route — anyone can fill your ImageKit quota. Fix: require admin session on upload, list, and delete.
- Trusting any MIME from the client — rename tricks exist. Fix: allowlist
image/jpeg|png|webp|gifand size-cap on the server.
Frequently Asked Questions
What is ImageKit Nuxt upload?
It is uploading files to ImageKit from a Nuxt app while keeping the private API key on the server. The browser sends the file to your Nitro route (or uses short-lived auth params), and you store the returned CDN URL on the content record.
How do I get started with ImageKit in Nuxt?
Create an ImageKit account, copy URL endpoint + public + private keys into server env, add a protected /api/imagekit/upload route with @imagekit/nodejs, then point your admin uploader at that route after compressing the image.
ImageKit vs Supabase Storage?
Pick Supabase Storage when images should live next to your Postgres project and RLS policies. Pick ImageKit when you want CDN transforms, a dedicated media library UI, and lighter app-side image work. Many apps start on Supabase and move hot media to ImageKit later.
Is ImageKit worth it for a portfolio blog?
Yes if you publish often and care about cover/OG performance without maintaining your own image pipeline. If you only upload a few images a year, Supabase Storage alone is enough.
Summary
Treat ImageKit like any other secret-backed API: Nitro holds the private key, the admin UI only posts files and saves CDN URLs. Get env + auth right first; the upload SDK call is the easy part.
Today: add the three env keys, hit your upload route once from admin, and confirm the file lands under portfolio/posts in the ImageKit Media Library.
Key Takeaways
- Never put
IMAGEKIT_PRIVATE_KEYin Nuxt public runtime config. - Upload (or sign) on the server; store only the public CDN URL in the CMS.
- Compress before upload and namespace folders under a single root like
portfolio/posts. - Protect upload, list, and delete with the same admin auth as publish.
- Restart the server after env changes — empty runtime config is a common false “ImageKit broken” report.

Comments
0 comments · new ones appear after approval
No comments yet. Be the first to share your thoughts.
Leave a comment
Your comment will be reviewed before it appears.