I’m struggling with uploading files to a Team Drive using Google Drive API V3. Can someone help me figure out what I’m doing wrong?
I keep getting a 404 error when trying to upload files to our shared drive. I tried using the parent folder ID but it doesn’t work properly.
Here’s my current code:
function uploadToTeamDrive(fileStream, fileSize, mimeType, filename, folderId, onComplete) {
// Setup progress tracking
this.emit('upload-progress', {
category: 'document',
filename: filename,
bytesUploaded: 0,
totalBytes: fileSize
});
console.log('Starting upload for %s with folder ID: %s', filename, folderId);
const driveService = google.drive({ version: 'v3', auth: this.authClient });
let documentMetadata = {
name: filename,
mimeType: mimeType,
'parents': ["0BFjjwdVdxetuUk9PVB"],
'sharedDriveId': "0BFjjwdVdxetuUk9PVB"
}
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("upload-complete", {
totalBytes: fileSize,
filename: filename,
errorStatus: error
});
if (onComplete)
onComplete(error, response);
});
return uploadRequest;
}
The error I’m getting is:
code: 404,
errors: [{
domain: 'global',
reason: 'notFound',
message: 'File not found: 0BFjjwdVdxetuUk9PVB.',
locationType: 'parameter',
location: 'fileId'
}]
What am I missing here? Do I need special permissions or different parameters for Team Drive uploads?