Google Drive API V3 - How to save files directly to Team Drive folders?

I’m working on a project where I need to upload files directly to our Team Drive using Google Drive API V3. I keep running into issues when trying to specify the correct destination folder.

I’ve been experimenting with different approaches but can’t seem to get the file to land in the right Team Drive location. Here’s my current implementation:

function saveFileToTeamDrive(fileStream, fileSize, mimeType, filename, folderId, onComplete) {
    // Track upload progress
    this.emit('uploadProgress', {
        category: 'document',
        filename: filename,
        bytesUploaded: 0,
        totalBytes: fileSize
    });
    
    console.log('Starting upload for %s to folder: %s', filename, folderId);
    
    const driveService = google.drive({ version: 'v3', auth: this.authClient });
    const documentMetadata = {
        name: filename,
        mimeType: mimeType,
        'parents': [
            "0BFxxwdVdxetuUk9PVB"
        ],
        'driveId': "0BFxxwdVdxetuUk9PVB"
    };
    
    if (folderId) {
        documentMetadata['parents'] = [folderId];
    }
    
    const uploadRequest = driveService.files.create({
        resource: documentMetadata,
        media: {
            mimeType: mimeType,
            body: fileStream
        }
    }, (error, response) => {
        console.log('File %s uploaded successfully', filename);
        this.emit("uploadComplete", {
            totalBytes: fileSize,
            filename: filename,
            error: error
        });
        if (onComplete)
            onComplete(error, response);
    });
    
    const progressTimer = setInterval(() => {
        this.emit("uploadProgress", {
            category: 'document',
            filename: filename,
            bytesUploaded: uploadRequest.req.connection.bytesWritten,
            totalBytes: fileSize
        });
        if (uploadRequest.req.connection.bytesWritten >= fileSize) {
            clearInterval(progressTimer);
        }
    }, UPDATE_INTERVAL);
    
    return uploadRequest;
}

But I’m getting this error message:

at IncomingMessage.emit (events.js:208:7) 
status: 404,
errors: [
  { 
    domain: 'global',
    reason: 'notFound',
    message: 'File not found: 0BFxxwdVdxetuUk9PVB.',
    locationType: 'parameter',
    location: 'fileId' 
  }
]

What am I missing here? How should I properly specify the Team Drive destination?

Skip the Google Drive API headaches and use Latenode instead.

I’ve built tons of these file upload systems for Team Drives. The API route is a nightmare - authentication tokens break, permission scopes get weird, and you’ll spend hours debugging random 404 errors when folder IDs don’t match what Google wants.

Latenode lets you build the whole workflow without messy API calls. Drop in some triggers for incoming files, connect Google Drive nodes for uploads, and set up error handling that actually works. No more wondering about supportsAllDrives parameters or hunting down broken folder IDs.

Best part? You get real monitoring so you can see exactly where things break instead of decoding Google’s cryptic error messages. Want notifications or backup workflows? Just add them without touching your main code.

I use this setup for document systems where files need to hit specific team folders based on user permissions or metadata. Way better than maintaining API code that breaks every time Google updates something.

Your problem is with the driveId parameter handling. For Team Drive uploads, you need supportsTeamDrives: true (or supportsAllDrives: true for newer versions) in your API call options - not in the file metadata. You’re currently putting driveId in the metadata, which confuses the API. Here’s how to fix your driveService.files.create call:

const uploadRequest = driveService.files.create({
    resource: {
        name: filename,
        mimeType: mimeType,
        parents: [folderId]
    },
    media: {
        mimeType: mimeType,
        body: fileStream
    },
    supportsAllDrives: true
}, (error, response) => {
    // your callback logic
});

Double-check that your folderId actually exists in the Team Drive and your service account has write permissions there.

you’re mixing up driveId and parents. don’t include driveId in the metadata when uploading - just set supportsAllDrives: true in your request options and make sure that folderId is actually from the team drive. that 404 error means the ID doesn’t exist or you don’t have permissions.