How can I save student files to teacher's Google Drive folder using React and NestJS?

My Setup

I’m building an assignment system where:

  • Teachers create tasks and choose a Google Drive folder for submissions
  • Students upload their work directly to the teacher’s selected folder

Current Implementation

I’m using Google Picker API in React to let teachers browse and select folders from their Drive. After selection, this folder info gets sent to my NestJS backend.

Questions I Need Help With

What folder information should I send from React to NestJS? Should I pass the folder ID, some kind of authorization token, or other data?

How do I actually upload student files to the teacher’s folder? I need the backend to save uploaded files directly to the previously chosen Google Drive location.

I’ve seen examples of uploading files to your own Drive, but I’m stuck on how to upload to someone else’s Drive folder. Any guidance would be really helpful!

// Example of what I'm trying to achieve
const handleAssignmentSubmission = async (studentFile) => {
  const submissionData = {
    file: studentFile,
    targetFolderId: teacherFolderId,
    studentId: currentStudent.id
  };
  
  await axios.post('/api/assignments/submit', submissionData);
};

Been there. You can’t just use the folder ID - you need proper permissions first. Have the teacher share the folder with your service account email and give it editor access. Or if you’re on G Suite, use domain-wide delegation. For the backend: store the folder ID when the teacher picks it, then use Google Drive API with your service account to upload files. Just make sure your service account can actually write to that folder before trying anything. Pro tip: always test folder access before students can submit. I’ve seen uploads fail during deadline crunch because someone changed permissions. Not fun.

make sure the teacher grants your app write permissions. send the folder ID and an access token that has write access for that folder. if you don’t have the correct OAuth scope, uploads won’t work.

I’ve built something like this before. Skip the direct access tokens - use folder sharing instead. Have teachers share their folder with a dedicated service account email (don’t use individual student accounts). Store the folder ID in your database with the assignment details. Your NestJS backend authenticates with the service account credentials and handles uploads through the Drive API. The tricky bit is permissions - I create a subfolder for each student inside the teacher’s main folder. Keeps everything organized. One gotcha: always validate the service account still has access before uploading. Teachers accidentally revoke sharing all the time, and you don’t want silent failures.