2010-06-21 50 views

回答

1

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

FUNC重刑讀取文件大小

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

而且還需要修改谷歌的GDATA python庫來實現這一目標:

client.py:

在 高清upload_file

取代:

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 

而且你可以上傳文件目錄谷歌文檔

3

the documentation,但你可以嘗試這樣的:

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 
+0

嗨, 我已經從這個了。我正在使用網絡表單上傳我的文件在Google應用引擎中,現在我想將該文件存儲在Google文檔中 我正在爲該問題找到解決方案 – 2010-06-21 07:58:54