文档列表API回归:更新文档(进行转换)会丢失图像 [英] Documents List API Regression: Updating a document (with conversion) loses images

查看:81
本文介绍了文档列表API回归:更新文档(进行转换)会丢失图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用文档列表API时,Google Docs转换最近似乎有问题.对现有文档条目进行的更新将无法正确转换为Google文档格式,并且文档中的图像也不会显示.

Something seems to have recently broken with the Google Docs conversion when using the documents list API. Updates made to existing document entries won't be converted into the Google Docs format correctly and images in the document will not appear.

  1. 我有一个.docx文件,其中包含几行文本和一张图片.

  1. I have a .docx file that has a couple lines of text, and an image.

使用文档列表API,我将文件作为NEW条目(转换已打开)上载,并且工作正常.我可以在Google文档中打开转换后的文档,看起来不错.

Using the documents list API, I upload the file as a NEW entry (with conversion turned ON), and it works fine. I'm able to open the converted document in Google Docs and it looks fine.

接下来,使用API​​之类的文档,将文件作为UPDATE再次上传到原始条目(启用转换).现在,当我在Google文档中打开转换后的文档时,图像丢失了.有一个带有旋转忙碌指示器的空白矩形,出现在应该放置图像的位置.

Next, using the documents like API, I upload the file again as an UPDATE to the original entry (with conversion turned on). Now when I open the converted document in Google Docs, the images are missing. There is a blank rectangle with a spinning busy indicator that appears where the images are supposed to be.

其他信息

因此,该问题仅在更新 现有条目时才会发生.作为全新条目上传的文件没有此问题.

Additional Info

So the problem only happens when updating the existing entry. Files uploaded as brand new entries don't have this problem.

必须在最近的24小时内损坏...我有一个运行良好的现有应用程序,现在它更新的所有文档都缺少图像.后端有没有更新导致该中断的消息?

This must have broken within the last 24 hours or so...I have an existing app that was working fine, and now all the documents that it updates have their images missing. Did something get updated on the backend that caused this to break?

我已经使用包含各种图像的各种.docx和.doc文件对此进行了测试.

I've tested this with a variety of .docx and .doc files containing a variety of images.

请帮助...这已经完全坏了一个星期了.我只想知道这是否是Google工程师意识到的问题,是否有人正在调查.

PLEASE, HELP...this has been totally BROKEN for a week now. I'd just like to know if this is an issue that the engineers at Google are aware of and if someone is looking into it.

推荐答案

(2020年10月):是2020年,这个问题确实过时了. Google 文档列表API

(Oct 2020): It's 2020, and this question is really outdated. The Google Documents List API was deprecated in 2012 and shutdown in 2015, replaced by the Google Drive API.

Drive API能够导入(上传和转换)Word文件(无论是使用图像创建还是使用图像更新到Google Docs格式),都不会出现问题.以下是这两种情况的一些伪代码(Python). 1号上传一个名为person.docx的Word文件,其中有一个图像.上传后,会向用户显示一条消息,您可以验证图像是否在Google文档中.

The Drive API is able to import (upload & convert) a Word file whether creating or updating with images into Google Docs format without issue. Below is some pseudocode (Python) for both cases. The 1st uploads a Word file named person.docx which has an image. After it uploads, a message is displayed to the user, and you can verify the images are in the Google Doc.

DOCX_FILE = 'person.docx'
DOCS_MIME = 'application/vnd.google-apps.document'
    :
    : # credentials code for user acct auth (OAuth client ID) or service acct auth
    :
DRIVE = discovery.build('drive', 'v3', ...) # http= or creds= dep on auth type
body = {'name': DOCX_FILE, 'mimeType': DOCS_MIME}
res = DRIVE.files().create(media_body=DOCX_FILE, body=body,
        fields='name,mimeType').execute()
print('Uploaded "%s" (as %s)' % (res['name'], res['mimeType']))

正如OP所提到的,创建文件与以前一样完美.如果您编辑现有文档,则除了像以前一样提供文件有效负载之外,还需要提供其云端硬盘文件ID,然后调用files().update()而不是files().create(),它也可以正常工作:

As the OP mentions, creating a file works perfectly as before. If you edit an existing Doc, you need to provide its Drive file ID in addition to the file payload as before, and call files().update() instead of files().create(), and it works as well:

DRIVE_ID = 'YOUR_FILE_ID'. # existing file in Drive
DOCX_FILE = 'person.docx'  # Word file to replace the above file with
DOCS_MIME = 'application/vnd.google-apps.document'
    :
    : # credentials code as above
    :
DRIVE = discovery.build('drive', 'v3', ...) # same as above
body = {'name': DOCX_FILE, 'mimeType': DOCS_MIME}
res = DRIVE.files().update(fileId=DRIVE_ID, media_body=DOCX_FILE,
        body=body, fields='name,mimeType').execute()
print('Updated "%s" (as %s)' % (res['name'], res['mimeType']))

如果您是Drive API的新手,请继续阅读.要处理驱动器中已经存在 的文档(特别是面向面向文档的的操作),您可以使用Google Docs,Sheets和Slides API,但要执行 file 访问权限(例如导入/导出,复制,移动,重命名等),请使用 Google云端硬盘API .如果您是Drive API的新手,那么除了上面的示例外,还有一些示例:

If you're new to the Drive API, read on. For manipulating documents that are already in Drive, specifically document-oriented operations, you'd use the Google Docs, Sheets, and Slides APIs, but to perform file-level access such as imports/exports, copy, move, rename, etc., use the Google Drive API instead. If you're new to the Drive API, here are some examples aside from the above:

  • Listing your files in Google Drive and code deep dive post -- useful for if you're unfamiliar w/the auth code referred to above
  • Google Drive: Uploading & Downloading Files plus "Poor man's plain text to PDF converter" code deep dive post (*)
  • Exporting a Google Sheet as CSV blog post only

(*)-TL; DR:将纯文本文件上传到云端硬盘,导入/转换为Google文档格式,然后将该文档导出为PDF.以上发布内容使用Drive API v2; 此后续帖子描述了如何将其迁移到Drive API v3,这是一个开发者视频将两个穷人的转换器"组合在一起帖子.

(*) - TL;DR: upload plain text file to Drive, import/convert to Google Docs format, then export that Doc as PDF. Post above uses Drive API v2; this follow-up post describes migrating it to Drive API v3, and here's a developer video combining both "poor man's converter" posts.

要了解有关一般如何将Google API与Python结合使用的更多信息,请查看我的博客以及各种Google开发者视频(系列1

To learn more about how to use Google APIs with Python in general, check out my blog as well as a variety of Google developer videos (series 1 and series 2) I've produced.

这篇关于文档列表API回归:更新文档(进行转换)会丢失图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆