2012-04-09 106 views
2

我設法創建了一個簡單的應用程序,它可以刪除(繞過回收站)任何我想要的文件。它也可以上傳文件。我遇到的問題是我無法指定新文件應該上傳到哪個集合。Google文檔python gdata 2.0.16將文件上傳到現有集合

def UploadFile(folder, filename, local_file, client): 
    print "Upload Resource" 
    doc = gdata.docs.data.Resource(type='document', title=filename) 
    path = _GetDataFilePath(local_file) 
    media = gdata.data.MediaSource() 
    media.SetFileHandle(path, 'application/octet-stream') 
    create_uri = gdata.docs.client.RESOURCE_UPLOAD_URI + '?convert=false' 
    collection_resource = folder 
    upload_doc = client.CreateResource(doc, create_uri=create_uri, collection=collection_resource, media=media) 
    print 'Created, and uploaded:', upload_doc.title, doc.resource_id 

從我理解的函數CreateResources需要一個資源對象表示集合。我如何獲得這個對象?變量文件夾當前只是一個字符串,它表示'daily'是集合的名稱,它是我需要用集合資源替換的這個變量。

回答

3

從各種來源,片段和一般東西到我設法解決這個問題。您需要將uri傳遞給FindAllResources函數(我在gdata的示例代碼中找不到任何代碼)。

我有更多的細節寫了我如何成功上傳,刪除(繞過垃圾桶),搜索和移動文件到集合

here

相關問題