This guide will help you set up Google Apps Script to handle file uploads to Google Drive. This is much simpler than Google Cloud Console setup - no OAuth tokens needed!
✅ No OAuth setup required
✅ No credentials to manage
✅ Free and easy to deploy
✅ Built-in Drive and Sheets integration
✅ Perfect for MVP
- Go to Google Apps Script
- Click "+ New project"
- Name it:
PrintX Drive Upload - Delete the default
myFunctioncode - Copy the entire content from
apps-script/Code.gsand paste it into the editor - Click "Save" (💾 icon) or press
Cmd+S/Ctrl+S
- Go to Google Drive
- Create a new folder named
PrintX Orders(or any name you prefer) - Right-click the folder and select "Share"
- Make it accessible to your Google account (or "Anyone with the link" if needed)
- Copy the folder ID from the URL:
- URL format:
https://drive.google.com/drive/folders/FOLDER_ID_HERE - The
FOLDER_ID_HEREis what you need
- URL format:
- In your Apps Script, replace
YOUR_DRIVE_FOLDER_ID_HEREwith your actual folder ID
- Go to Google Sheets
- Create a new spreadsheet named
PrintX Orders Log - Copy the Sheet ID from the URL:
- URL format:
https://docs.google.com/spreadsheets/d/SHEET_ID_HERE/edit - The
SHEET_ID_HEREis what you need
- URL format:
- In your Apps Script, replace
YOUR_SHEET_ID_HEREwith your actual Sheet ID - Or leave it as
YOUR_SHEET_ID_HEREto disable sheet logging
In Code.gs, update these values:
const FOLDER_ID = 'your_actual_folder_id_here';
const SHEET_ID = 'your_actual_sheet_id_here'; // Or leave as is to disable- In Apps Script editor, click "Deploy" > "New deployment"
- Click the gear icon (⚙️) next to "Select type"
- Choose "Web app"
- Configure:
- Description:
PrintX File Upload Service - Execute as: "Me" (your account)
- Who has access: "Anyone" (or "Anyone with Google account" for more security)
- Description:
- Click "Deploy"
- Authorize the app:
- Click "Authorize access"
- Choose your Google account
- Click "Advanced" > "Go to [Project Name] (unsafe)"
- Click "Allow"
- Copy the Web App URL - You'll need this for your Next.js app
- Open the Web App URL in your browser
- You should see:
{"status":"ok","service":"PrintX Drive Upload",...} - If you see an error, check the authorization and try again
-
Create
.env.localfile (if not exists):APPS_SCRIPT_WEB_APP_URL=https://script.google.com/macros/s/YOUR_WEB_APP_ID/exec
-
Replace
YOUR_WEB_APP_IDwith the ID from your Web App URL
- Restart your Next.js dev server:
npm run dev - Upload a file through PrintX
- Check your Drive folder - the file should appear!
- (If enabled) Check your Google Sheet for the order log
- Make sure you saved the
Code.gsfile - Redeploy the web app after making changes
- Check that "Who has access" is set to "Anyone" (or your account has access)
- Re-authorize the app if needed
- Verify the folder ID is correct
- Check that the folder exists and is accessible
- Check Apps Script execution logs: "Executions" tab in Apps Script editor
- Apps Script has daily quotas (6 minutes execution time, 20,000 API calls/day)
- For production, consider upgrading or using Google Cloud
Apps Script Free Tier:
- 6 minutes execution time per request
- 20,000 API calls per day
- 100MB total request size
Your app is configured to:
- Max 10 files per request
- Max 50MB per file
- Max 100MB total per request
This should handle hundreds of orders per day easily!
- The Web App URL is public - anyone with the URL can upload files
- For production, consider:
- Using "Anyone with Google account" access
- Adding API key authentication
- Implementing rate limiting
- Moving to Google Cloud Functions for better security
- Monitor usage in Apps Script: "Executions" tab
- Set up email alerts for errors (optional)
- Organize files by date in Drive (modify script)
- Add file validation (file types, sizes)
- Consider upgrading to Google Cloud for production scale
- Apps Script Documentation: https://developers.google.com/apps-script
- Drive API: https://developers.google.com/drive/api
- Check execution logs in Apps Script editor for detailed errors