0

I created a new google doc successfully in my drive, but now I wish to change the file type from 'application/msword' to 'application/vnd.google-apps.document'.

I tried to use the answer here to copy the file, but it's not working:

convert a Word doc into a Google doc using the API via nodejs using drive.files.copy convert in v3 of Google Drive API

The code I have is similar to the above question.

After I create the document as msword I am trying to make a simple copy to convert it to a google doc.

drive.files.create({
    requestBody: body.requestBody,
    fields: 'id',
  }, function (err: any, file: any) {
    if (err) {
      console.error(err);
    } else {


      drive.files.copy(
        {
          fileId:  file.data.id,
          requestBody: {  // You can also use "resource" instead of "requestBody".
            name: 'copy',
            mimeType: "application/vnd.google-apps.document"
          }
        },
        (err, res) => {
          if (err) return console.log("The API returned an error: " + err);
          console.log(res.data);  // If you need, you can see the information of copied file.
        }
      );


    }

the error I'm getting is

Conversion of the uploaded content to the requested output type is not supported.

Any help is appreciated, thanks!

Louis Sankey
  • 481
  • 8
  • 26
  • I was able to reproduce the exact same issue after creating a blank document using the file type application/msword with the Drive API. I was also unable to open the document in the web UI. This did not happen if I just created the file directly from Word and manually uploaded the file to Google Drive, meaning that something related to the file creation may be causing the problem. Have you tested this so far with a different file? Are you able to open this exact same document using the web UI? Since you mentioned that you are also creating the files, are you creating blank files as well? – Fernando Lara Apr 13 '22 at 20:37
  • @FernandoLara thanks, yes was having a similar experience. I think fixed the problem. I needed to update the file with some content after creation. ` drive.files.update({ fileId: file.data.id, media: body.media, });` Now I am able to open it in the web UI and make the copy. – Louis Sankey Apr 13 '22 at 22:24

1 Answers1

0

After making some tests with different mime types from Microsoft Office, it looks like the Office editing mode from Google Drive is unable to read blank files and therefore you were getting the error message.

If I am not mistaken, the way Google Drive works to change files formatting is that they need to open the file first in order to read the information and change the formatting. However, in this case Google Drive is recognizing these blank files as corrupted files and is unable to open them using the Office editing mode.

This looks like an expected behavior but could also be considered as a bug from this specific feature. I would recommend you to post your question in the Google Issue Tracker and explain the behavior and testing you have done so far so that you can confirm if this is just expected or a bug from the Office editing mode.

Reference:

Fernando Lara
  • 2,263
  • 2
  • 4
  • 14