Prerequisites
- Node.js 18+
- A SyncSnap project and API key from the dashboard (or your backend that creates jobs and returns download URLs)
- Next.js app using the App Router
Step 1: Install packages
Step 2: Environment variable
Your server needs the SyncSnap API key. In.env.local:
Step 3: API route
Create the SyncSnap API route so the frontend can create jobs and wait for completion (and optionally get download URLs). Create this file:app/api/syncsnap/[...syncsnap]/route.ts
POST /api/syncsnap/job— create jobGET /api/syncsnap/job/:id— get jobGET /api/syncsnap/job/:id/wait— server waits until job completes, then returns{ job, result? }(result is from youronCompletedcallback or the presigned URL)GET /api/syncsnap/job/:id/download— get presigned download URL
Step 4: Add the upload button
In any client component:Step 5: Styles (Tailwind)
The button and dialog use Tailwind and the SDK theme. In your main CSS (e.g.app/globals.css):
Step 6: Run and test
- Start the dev server:
npm run dev - Open the page and click Scan to upload.
- A dialog opens with a QR code. Scan it with your phone and upload a file.
- When the job completes,
onCompletedruns and you can use the presigned download URL.