☁️ Google Drive Photo Setup
Connect your school's Google Drive to store student photos permanently
Checking connection…
Please wait
Google Apps Script Web App URL
Paste the URL you got after deploying the Apps Script (ends with
/exec)
Test Photo Upload
Take a live photo or pick from gallery to confirm photos reach Google Drive successfully.
Setup Instructions (One-time, ~5 minutes)
1
Open Google Apps Script
Go to script.google.com and sign in with the school's Google account.
Click New Project.
2
Paste the Script Code
Delete any existing code in the editor, then paste the script below. Click the 💾 save icon.
/**
* ALIF ERP — Google Drive Photo Storage
* Deploy as: Web App → Execute as: Me → Who has access: Anyone
*/
function doPost(e) {
try {
var data = JSON.parse(e.postData.contents);
var imageBase64 = data.imageData.replace(/^data:image\/(png|jpeg|jpg|webp);base64,/, '');
var studentId = data.studentId || 'unknown';
var studentName = (data.studentName || 'Student').replace(/[^a-zA-Z0-9 _-]/g, '');
var folderName = 'ALIF ERP — Student Photos';
var folders = DriveApp.getFoldersByName(folderName);
var folder = folders.hasNext() ? folders.next() : DriveApp.createFolder(folderName);
// Remove old photo for this student (if any)
var oldFiles = folder.getFilesByName('student_' + studentId + '.jpg');
while (oldFiles.hasNext()) { oldFiles.next().setTrashed(true); }
// Save new photo
var fileName = 'student_' + studentId + '.jpg';
var blob = Utilities.newBlob(Utilities.base64Decode(imageBase64), 'image/jpeg', fileName);
var file = folder.createFile(blob);
file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
var fileId = file.getId();
var viewUrl = 'https://lh3.googleusercontent.com/d/' + fileId;
return ContentService
.createTextOutput(JSON.stringify({ success: true, fileId: fileId, url: viewUrl }))
.setMimeType(ContentService.MimeType.JSON);
} catch(err) {
return ContentService
.createTextOutput(JSON.stringify({ success: false, error: err.message }))
.setMimeType(ContentService.MimeType.JSON);
}
}
function doGet(e) {
return ContentService
.createTextOutput(JSON.stringify({ status: 'ok', service: 'ALIF ERP Photo Service' }))
.setMimeType(ContentService.MimeType.JSON);
}
3
Deploy as Web App
Click Deploy → New Deployment.
Set Type: Web app.
Set Execute as: Me (your Google account).
Set Who has access: Anyone.
Click Deploy → authorize when prompted.
Set Type: Web app.
Set Execute as: Me (your Google account).
Set Who has access: Anyone.
Click Deploy → authorize when prompted.
4
Copy the Web App URL
After deployment, a URL appears. It looks like:
Copy this URL — you need it for the next step.
https://script.google.com/macros/s/AKfy…/execCopy this URL — you need it for the next step.
5
Paste URL above and click Save & Test ✅
Paste the Web App URL in the field at the top of this page and click Save & Test.
You should see a green "Connected!" status.
How to Upload Student Photos
📱
From Students Page
Open Students page → click the 📷 icon on any student → choose Take Live Photo or Choose from Gallery → auto-uploads to Drive.
👁️
From Student Profile
Click any student's name → open profile → tap the 📷 overlay on the avatar → pick camera or gallery — photo uploads instantly.
🎓
Teacher & Parent App
Teachers tap 📷 on a student's avatar in their dashboard. Parents tap 📷 on the child hero card — both get the live/gallery picker.
🪪
ID Card Printing
Once photos are uploaded, they auto-appear on ID cards. Go to ID Cards page → select students → print.
Troubleshooting
Upload says "Saved locally" even with URL set
The Apps Script may not be deployed correctly. Re-deploy:
Script editor → Deploy → Manage Deployments → Edit (pencil) → New Version → Deploy.
Make sure Who has access is set to Anyone (not "Anyone with Google account").
Also check: tap Test Photo Upload above → pick any image → see if the result says ✅ or ❌.
Script editor → Deploy → Manage Deployments → Edit (pencil) → New Version → Deploy.
Make sure Who has access is set to Anyone (not "Anyone with Google account").
Also check: tap Test Photo Upload above → pick any image → see if the result says ✅ or ❌.
Test returns "Could not verify" but might still work
This is normal — some browsers block cross-origin GET requests even when the URL is correct. Try the Test Photo Upload button above instead, which does a real upload.
Photo uploaded but not showing in ID card
Google Drive image URLs (
lh3.googleusercontent.com) sometimes take 1–2 minutes to become publicly accessible after first upload. Wait a moment, then refresh the ID Cards page.
Where are the photos stored in Google Drive?
All photos are saved inside a folder named "ALIF ERP — Student Photos" in the Google Drive of the account you used to deploy the Apps Script. Each file is named
student_[ID].jpg.