*Hi, Using Google Drive API to upload files in the Drive. The file gets uploaded successfully but in response, the file ID is showing undefined. I have to use the file id for further code *
function uplodeFile(auth){
const drive = google.drive({version: 'v3', auth});
var fileMetadata = {
'name': 'error.jpg'
};
var media = {
mimeType: 'image/jpeg',
body: fs.createReadStream('Capture.JPG')
};
drive.files.create({
resource: fileMetadata,
media: media,
fields: 'id'
}, function (err, file) {
if (err) {
// Handle error
console.error(err);
} else {
console.log('File Id: ', file.id);
}
});
}
If you are using the latest version of googleapis for Node.js, how about the following modification?
console.log('File Id: ', file.id);
console.log('File Id: ', file.data.id);
v61.0.0
.