簡體   English   中英

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

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

我想使用Google Apps Engine(python)將文檔,文件上傳到Google文檔

任何代碼或鏈接將不勝感激

請參閱文檔,但您可以嘗試以下方法:

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

解決方案是文件上傳,你需要在python中使用下面的行讀取數據:

函數讀取文件大小

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

而且還需要修改Google的gdata python庫來實現這個目的:

client.py:

在def upload_file中

更換:

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

附:

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

您可以將文件目錄上傳到谷歌文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM