I need to upload a .doc or .docx file to google drive using Google Drive API v3 then convert it also using Google Drive API v3 so that the content of the file will be readable and editable in my own web application (hosted in node.js). I have tried to do this using drive.files.copy, however, I kept on receiving the error: The API returned an error: Error: Conversion of the uploaded content to the requested output type is not supported. Can anyone help me in figuring out how to do this? Any help will be greatly appreciated. Thank you!
Here is the code that I used for converting, however, it is not working:
drive.files.list({
q: "mimeType = 'application/msword'"
pageSize: 100,
fields: 'nextPageToken, files(id, name)',
}, (err, res) => {
if (err) return console.log('The API returned an error: ' + err);
const files = res.data.files;
if (files.length) {
console.log('Files:');
files.map((file) => {
let result = (file.name).substring(0, (file.name).indexOf('.'));
console.log(file);
console.log(`${file.name} (${file.id})`);
drive.files.copy(
{
fileId: file.id,
requestBody: {
name: result,
mimeType: 'application/vnd.google-apps.document'
}
},
(err, res) => {
if (err) return console.log("The API returned an error: " + err);
console.log(res.data);
}
);
});
}else {
console.log('No files found.');
}
});
Here is the code I used for uploading the file:
const driveResponse = drive.files.create({
requestBody: {
name: filename,
mimeType: mimetype
},
media: {
mimeType: mimetype,
body: Buffer.from(data).toString()
}
});
driveResponse.then(data => {
if(data.status == 200)
res.redirect('/notes');
else
console.log("file not uploaded.");
}).catch(err => { throw new Error(err) })