Google Drive API V3 - Uploading files to Shared Drive throws 404 error

I’m trying to upload a file to a Shared Drive using Google Drive API V3 but keep getting a 404 error. When I specify the parent folder ID for the Shared Drive, it says the file is not found.

function uploadToSharedDrive(fileStream, fileSize, mimeType, name, folderId, done) {
    // Progress tracking
    this.emit('uploadStart', {
        filename: name,
        bytes: 0,
        total: fileSize
    });
    
    const driveClient = google.drive({ version: 'v3', auth: this.authClient });
    const metadata = {
        name: name,
        mimeType: mimeType,
        parents: ["0BXiiwdVdxetuUk9PVA"],
        teamDriveId: "0BXiiwdVdxetuUk9PVA"
    };
    
    if (folderId) {
        metadata.parents = [folderId];
    }
    
    const request = driveClient.files.create({
        resource: metadata,
        media: {
            mimeType: mimeType,
            body: fileStream
        }
    }, (error, response) => {
        this.emit('uploadComplete', {
            filename: name,
            error: error
        });
        if (done) done(error, response);
    });
    
    return request;
}

The error I’m getting is:

code: 404,
errors: [{
    domain: 'global',
    reason: 'notFound', 
    message: 'File not found: 0BXiiwdVdxetuUk9PVA.',
    locationType: 'parameter',
    location: 'fileId'
}]

What’s the correct way to upload files to a Shared Drive? Am I missing some configuration or using the wrong approach?

Had this exact headache a few months back. You’re mixing old Team Drive syntax with new Shared Drive calls. Remove teamDriveId from your metadata object completely and add supportsAllDrives: true plus includeItemsFromAllDrives: true to your driveClient.files.create parameters. Also check that your parents array has a valid folder ID within the shared drive, not the shared drive root ID itself. If you’re uploading to the shared drive root, you need to get the actual root folder ID first with a separate API call. The 404 usually means the API can’t find the parent folder with your current auth context.

The problem’s your teamDriveId parameter - it’s deprecated. Switch to driveId and add supportsAllDrives: true to your API call. I hit this same issue last year migrating an old project. Here’s what fixed it: const request = driveClient.files.create({ resource: metadata, media: { mimeType: mimeType, body: fileStream }, supportsAllDrives: true }, (error, response) => { // your callback }); Drop teamDriveId from your metadata completely. Your parents array needs the actual folder ID inside the Shared Drive, not the Shared Drive ID. And make sure your service account’s actually added to the Shared Drive with the right permissions.

Check your auth scope - you probably need https://www.googleapis.com/auth/drive instead of just https://www.googleapis.com/auth/drive.file for shared drives. I hit the same 404s until I switched scopes. Also do a quick GET request to verify the folder ID actually exists - they sometimes change or get moved around.