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?