4
votes

I am trying to export a docx file to zipped html using Google Drive API (Save as zipped html is one of the feature of google docs). But as per the documentation, supported export mime types are. https://developers.google.com/drive/manage-downloads

text/html

text/plain

application/rtf

application/vnd.oasis.opendocument.text

application/pdf

application/vnd.openxmlformats-officedocument.wordprocessingml.document

UPLOAD code

file = drive.files.insert.request_schema.new({
         'title' => 'My document',
         'description' => 'A test document',
         'mimeType' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
     }
)
media = Google::APIClient::UploadIO.new('gdoc.docx', 'application/msword')
result = client.execute(
    :api_method => drive.files.insert,
    :body_object => file,
    :media => media,
    :parameters => {
        'uploadType' => 'multipart',
    'convert' => 'true'
    }
)

DOWNLOAD code

download_url =  result.data.to_hash['exportLinks']['text/html']
html = client.execute(:uri => download_url)  

Can anyone please tell me how can I export google doc to zipped html ?

1
It seems like you have whole code of how to upload and download Google Docs as html file. Basically, zipped html file is equivalent to html file you download from the API.JunYoung Gwak
I am having the same problem. I have written the same code with the google api python client and it works fine. In this case, the json result from google after file upload doesn't have an exportLinks field like the documentation says. When I wrote this for python, I sometimes have the problem of missing exportLinks. In python I wait for 30 seconds and do a files.get for updated metadata. In ruby, it never shows up when I use the above code.Sethish
@Sethish that might be because you have not specified the convert option(which converts the file to google doc format) while uploading to google drive. You can export documents to other formats only if it is in google doc format.scanE
@scanE I'm passing the convert argument. You might consider passing a boolean instead of a string for true It might fix your version of this problem. Are you getting an exportLinks key?Sethish

1 Answers

0
votes

I have the same problem.

Apparently exporting a Google Document to mimeType="text/html" using the drive-API, is NOT the same as clicking that same document's "File > Download-As > Web Page (.html, zipped)" menu item.

  • In the export case, a file of 32k bytes is downloaded in a single html page.
  • In the "File > Download-As > Web Page (.html, zipped)" case, the .zip contains one file of 11k bytes
  • The content seems to be REALLY different.

I wonder if the Google Folks could please shed some light on this asymmetry.