使用Google App Engine如何在Google文档中上传文档(python) [英] Using Google App Engine how to upload document in google docs (python)

查看:155
本文介绍了使用Google App Engine如何在Google文档中上传文档(python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Google Apps Engine(python)将文档,文件上传到Google文档中



任何代码或链接都将被赞赏


功能 阅读文件大小

$ $ p $ $ $ c $ def $ getSize(self,fileobject)$ b $ fileobject.seek(0,2)#move游标到文件的末尾
size = fileobject.tell()
返回大小



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))

还需要修改Google的gdata python库可以实现这一点:

client.py:

in
def upload_file



替换:

  while not en尝试:
entry = self.upload_chunk(start_byte,self.file_handle.read(self.chunk_size))
start_byte + = self.chunk_size
$ b $



 而不是输入:
输入= self.upload_chunk(start_byte,self.file_handle)
start_byte + = self.chunk_size

您可以将文件目录上传到Google文档


I want to upload document, file to google docs using Google Apps Engine (python)

any code or link will be appreciated

解决方案

Solution is with files Upload, You need to read data using below line in 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:

client.py:

in 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

这篇关于使用Google App Engine如何在Google文档中上传文档(python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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