module-08-ship
Deploy and Ship
Pre-final · Module 8 — photos on Cloudinary, live URL on Vercel
2nd Year · BSIT
Student Marketplace
Cloudinary · Vercel
The finish line
You already have a real app
DONE
Pages + components
Navbar once. ListingCard. Home, detail, post — all .tsx.
DONE
Real rows
Neon + Prisma. Home reads the table. Refresh keeps the listing.
TODAY
Photos + a URL
Cloudinary stores the file. Vercel runs the app.
Why not a folder?
Vercel does not keep uploaded files
There is no permanent disk on Vercel. A file you save during one request is gone on the next.
Wrong idea
Save photo.jpg into a folder on the server. Works on localhost. Breaks after deploy.
Right idea
Upload the file to Cloudinary. Save the URL in the database. The listing stores a link, not a file.
Where things live
Three homes. One marketplace.
🖼
Cloudinary
The photo file
→
🗄
Neon
The imageUrl string
→
Cloudinary
Three secrets in .env
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secret
- Sign up at
cloudinary.com · copy the three values from the Dashboard
npm install cloudinary
- These are passwords. They stay in
.env with DATABASE_URL
API
app/api/upload/route.ts
import { v2 as cloudinary } from 'cloudinary';
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
});
export async function POST(request: Request) {
const formData = await request.formData();
const file = formData.get('file');
if (!(file instanceof File)) {
return Response.json({ error: 'No file' }, { status: 400 });
}
const buffer = Buffer.from(await file.arrayBuffer());
// upload_stream → result.secure_url
return Response.json({ url: result.secure_url });
}
Database
The listing must store the URL
data: {
title: body.title,
description: body.description,
price: parseFloat(body.price),
imageUrl: body.imageUrl,
}
- Update
POST in app/api/listings/route.ts — add imageUrl
- Module 7 already created the column. You just have to write it.
- Skip this and the photo uploads, then the card stays a placeholder
Component
ListingCard shows the real photo
type CardProps = {
title: string;
price: number;
imageUrl: string;
};
<img src={imageUrl} alt={title} />
- Pass
imageUrl={item.imageUrl} from home and detail
- Keep a placeholder URL only when the student skips the file
Post form
Add the file input first
const [imageFile, setImageFile] = useState<File | null>(null);
<input
type="file"
accept="image/*"
onChange={(e) => setImageFile(e.target.files?.[0] ?? null)}
/>
- Same page as Module 7:
app/post/page.tsx
imageFile is what the upload snippet uses next
- Photo is optional — leave it empty and keep the placeholder URL
Post form
Upload first, then save the row
1. Choose a file → imageFile
2. POST /api/upload → { url }
3. POST /api/listings → { title, price, description, imageUrl }
4. router.push('/')
let imageUrl = 'https://placehold.co/300x200';
if (imageFile) {
const uploadData = new FormData();
uploadData.append('file', imageFile);
const uploadRes = await fetch('/api/upload', { method: 'POST', body: uploadData });
imageUrl = (await uploadRes.json()).url;
}
await fetch('/api/listings', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title, price, description, imageUrl }),
});
Two requests. Same form. The database stores a link, not the photo bytes.
Before you deploy
Search the project for localhost:3000
Dies on Vercel
fetch('http://localhost:3000/api/listings')
localhost is the laptop. Vercel is a different machine. That URL never reaches Neon.
Already correct (Module 7)
await prisma.listing.findMany(...)
fetch('/api/listings')
fetch('/api/upload')
Prisma on home/detail. Relative /api/... on the form. No extra URL helper.
Vercel build
Tell Vercel to generate Prisma
{
"scripts": {
"dev": "next dev",
"build": "next build",
"postinstall": "prisma generate"
}
}
- Add
postinstall in package.json
- If the Vercel log mentions Prisma Client, this line is missing
GitHub
Push the app. Not the secrets.
git add .
git status
git commit -m "Student Marketplace ready to ship"
git push
- !
.env must not appear in git status
- ✓Public repo is fine — the URL is the point
Vercel
Import, paste four variables, Deploy
- 1vercel.com · sign in with GitHub · Add New Project
- 2Import your marketplace repo
- 3Environment Variables — all four, then Deploy
DATABASE_URL
CLOUDINARY_CLOUD_NAME
CLOUDINARY_API_KEY
CLOUDINARY_API_SECRET
The moment
Open it on your phone
No npm run dev. No laptop required. Same database. Same photos. A URL anyone can open.
- Post a listing with a real photo on the live URL
- Refresh — still there
- Send the URL to one classmate and ask them to post
Student Activity
Ship the marketplace
MUST HAVE
Upload API in route.ts · photo on the form · imageUrl saved · no localhost:3000 fetch · prisma generate on install
PROOF
Live Vercel URL. Post with a photo. Refresh. Open on a phone.
SUBMIT
The live URL (and GitHub repo). Not GitHub Pages — Vercel.
The course
Blank HTML → a URL on the internet
- 2Structure and design
- 3–4A form, then the three walls
- 5–6Why Next.js, then the upgrade
- 7–8A database, photos, and a live URL
You built this. Keep building.