How to transform Word documents to Google Docs format via Drive API v3

I’m working on a Node.js application and need to upload Word files (.doc/.docx) to Google Drive, then transform them into Google Docs format so users can edit them directly in my web app. I’ve been trying to use the files.copy method but keep getting an error saying the conversion isn’t supported. Has anyone successfully done this conversion?

My upload code:

const uploadResult = gdriveAPI.files.create({
    requestBody: {
        title: documentName,
        mimeType: fileType
    },
    media: {
        mimeType: fileType,
        body: Buffer.from(fileContent).toString()
    }
});

uploadResult.then(response => {
    if(response.status == 200)
        console.log('Upload successful');
    else
        console.log('Upload failed');
}).catch(error => { console.error(error) })

My conversion attempt:

gdriveAPI.files.list({
    q: "mimeType = 'application/msword'",
    pageSize: 50,
    fields: 'nextPageToken, files(id, name)'
}, (error, response) => {
    if (error) return console.log('API error: ' + error);
    const documents = response.data.files;
    if (documents.length) {
        documents.forEach((doc) => {
            let newName = (doc.name).split('.')[0];
            gdriveAPI.files.copy({
                fileId: doc.id,
                requestBody: {
                    name: newName,
                    mimeType: 'application/vnd.google-apps.document'
                }
            }, (error, result) => {
                if (error) return console.log('Conversion error: ' + error);
                console.log('Converted:', result.data);
            });
        });
    }
});

Any suggestions on the correct approach would be helpful!

You need to set the right parameters in your files.create call to convert Word docs during upload. Add uploadType: 'multipart' and supportsAllDrives: true to your request parameters. Then put the Google Docs mimeType in the requestBody but keep the original Word mimeType in the media section. I ran into this same issue last month when we migrated our company’s document workflow. The trick is letting the API handle conversion during upload instead of trying to do it after. Your Buffer.from() approach will definitely break with .docx files since they’re compressed archives. Use a proper stream or the file buffer directly in the media body. Also make sure you’re handling the v3 API response structure correctly - the file ID comes back in response.data.id, not response.id like older versions.

i got this working by switching to the import endpoint instead of create or copy. change your api call to files.create and add convertUploads: true in the params. fixed my conversion errors when the regular methods kept failing.

The copy method won’t handle the conversion properly. Use the create method instead and set the mimeType in requestBody to ‘application/vnd.google-apps.document’ while keeping the media mimeType as the original Word format. This makes Drive API convert the file during upload, not after. I ran into the same issue building a document management system last year. Google Drive converts automatically when you specify the target Google Docs mimeType in requestBody while uploading a supported format. Also, don’t use Buffer.from().toString() - it’ll corrupt binary Word files. Use fs.createReadStream() for the media body instead.