3
我想導出的docx文件使用谷歌雲端硬盤API壓縮HTML壓縮HTML(另存爲HTML壓縮是谷歌文檔的功能之一)。但根據文檔,支持的導出MIME類型。 https://developers.google.com/drive/manage-downloads出口DOCX使用谷歌API驅動
text/html的
純文本/
應用/ RTF
應用/ vnd.oasis.opendocument.text
應用/ PDF
應用/ VND。 openxmlformats-officedocument.wordprocessingml.document
上傳代碼
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_url = result.data.to_hash['exportLinks']['text/html']
html = client.execute(:uri => download_url)
誰能告訴我怎樣才能谷歌文檔導出爲HTML壓縮?
好像你對如何上傳和下載谷歌文檔爲HTML文件整個代碼。基本上,壓縮的html文件等同於您從API下載的html文件。 –
我遇到同樣的問題。我已經用google api python客戶端編寫了相同的代碼,並且工作正常。在這種情況下,文件上傳後google的json結果沒有像文檔中所說的「exportLinks」字段。當我爲python寫這篇文章時,我有時會遇到缺少'exportLinks'的問題。在python中,我等待30秒併爲更新的元數據執行'files.get'。在ruby中,當我使用上面的代碼時它從不顯示。 – Sethish
@Sethish可能是因爲您在上傳到谷歌驅動器時未指定轉換選項(將文件轉換爲Google文檔格式)。只有當它是Google Doc格式時,才能將文檔導出爲其他格式。 – scanE