Apps Script Web Apps don't automatically return CORS headers for POST requests from browsers, even when deployed with "Anyone" access. This causes CORS errors when trying to upload files directly from the browser.
Use the Vercel proxy (/api/proxy-upload) which:
- Handles CORS headers properly for browser requests
- Forwards requests to Apps Script server-to-server (no CORS needed)
- Allows chunking to stay under Vercel's 4.5MB limit per request
- Changed from direct Apps Script URL to Vercel proxy (
/api/proxy-upload) - Updated chunk size to 3MB per chunk (stays under 4.5MB when base64 encoded)
- Proxy handles CORS, forwards to Apps Script server-to-server
- Added fallback to use
NEXT_PUBLIC_APPS_SCRIPT_WEB_APP_URLifAPPS_SCRIPT_WEB_APP_URLis not set - Properly handles CORS headers for browser requests
- Maximum: 4.5MB per request
- Chunk Size: 3MB per chunk (becomes ~4MB when base64 encoded in JSON)
- Strategy: Files are automatically chunked if payload exceeds 3MB
- Maximum: 75MB per file (decoded)
- Total: 500MB total per order
- Max Files: 50 files per order
-
Client → Uploads files to
/api/proxy-upload(Vercel API)- CORS headers are set by the proxy
- Files are chunked if needed (3MB per chunk)
-
Vercel Proxy → Forwards to Apps Script (server-to-server)
- No CORS needed (server-to-server communication)
- Uses
APPS_SCRIPT_WEB_APP_URLorNEXT_PUBLIC_APPS_SCRIPT_WEB_APP_URL
-
Apps Script → Uploads to Google Drive
- Processes files and uploads to Drive
- Logs order data to Google Sheets
Set in Vercel Dashboard:
NEXT_PUBLIC_APPS_SCRIPT_WEB_APP_URL(client-side access)APPS_SCRIPT_WEB_APP_URL(server-side access, optional - proxy will use NEXT_PUBLIC_ if not set)
After deploying, test the upload:
- Go to your deployed site
- Upload a file
- Check browser console - should see:
[Upload] Using Vercel proxy: /api/proxy-upload (handles CORS, forwards to Apps Script) [Upload] Split X file(s) into Y chunk(s) for upload - Files should upload successfully without CORS errors
The CSP eval warning is likely a false positive. PDF.js is configured with isEvalSupported: false, so it doesn't use eval. The warning might be from:
- Browser extensions
- Other third-party libraries
- Browser's security scanner
If you see the warning but uploads work, you can safely ignore it. The CSP is correctly configured without unsafe-eval.