简体   繁体   English

使用Google App Engine如何在谷歌文档中上传文档(python)

[英]Using Google App Engine how to upload document in google docs (python)

I want to upload document, file to google docs using Google Apps Engine (python) 我想使用Google Apps Engine(python)将文档,文件上传到Google文档

any code or link will be appreciated 任何代码或链接将不胜感激

See the documentation, but you might try something like: 请参阅文档,但您可以尝试以下方法:

ms = gdata.MediaSource(file_path='/path/to/your/test.doc',  content_type=gdata.docs.service.SUPPORTED_FILETYPES['DOC'])
entry = gd_client.Upload(ms, 'MyDocTitle')
print 'Document now accessible online at:', entry.GetAlternateLink().href

Solution is with files Upload, You need to read data using below line in python: 解决方案是文件上传,你需要在python中使用下面的行读取数据:

function to read file size 函数读取文件大小

def getSize(self,fileobject):
  fileobject.seek(0,2) # move the cursor to the end of the file
  size = fileobject.tell()
  return size



f = self.request.POST.get('fname').file

media = gdata.data.MediaSource(file_handle=f.read(), content_type=gdata.docs.service.SUPPORTED_FILETYPES[ext], content_length=self.getSize(self.request.POST.get('fname').file))

And also need to modify the gdata python library of Google to achieve this: 而且还需要修改Google的gdata python库来实现这个目的:

client.py: client.py:

in def upload_file 在def upload_file中

replace: 更换:

while not entry:
 entry = self.upload_chunk(start_byte, self.file_handle.read(self.chunk_size))
 start_byte += self.chunk_size

With: 附:

while not entry:
  entry = self.upload_chunk(start_byte, self.file_handle)
  start_byte += self.chunk_size

And you can upload file directory to google doc 您可以将文件目录上传到谷歌文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM