我创建了一个烧瓶项目,在google驱动器上存储pdf。用户简单地在DIV上拖动pdf,并使用服务帐户将文件上传到云端硬盘。上传工作正常,但文件上传到根文件夹而不是子文件夹。服务帐户使用文件和文件夹所有者的凭据创建要在gdrive中输入的委托对象,但无法将文件上载到任何子文件夹,也无法读取文件夹的内容。
服务帐户是否需要任何特定权限才能读取和写入子文件夹?
问候,法比奥
C
答案 0 :(得分:0)
修复了一个问题,我只需登录管理控制台并按照service account page“将域范围的权限委派给服务帐户”中所述的说明进行操作。
然后我根据页面About authorization
选择了范围当我尝试将文件加载到子文件夹时,我仍然遇到问题,该文件进入根文件夹
答案 1 :(得分:0)
Ok I understood how to load files into subfolders too. The 'parents' metadata propety takes a list of folders, it means that a file will be uploaded in all the folders of the list at the same time.
The files are created with the same ID, so when I run drive_service.files().delete(fileId=id_file).execute() the file will be removed from every folder it was uploaded to.
In another thread I read that it's necessary to provide the "kind" property too, something like that:
[{"id": "XXXXXXXXXXXXXXXXXXX","kind": "drive#file"},{"id":"YYYYYYYYYYYYYYYYY","kind": "drive#file"}]
but it didn't work for me, but probably I misunderstood. A simple list object with the IDs of the folder is required, as shown below.
folder_id = [folder1, folder2, folder3]
body = {
'name': filename,
'mimeType': mime_type,
'useDomainAdminAccess':True,
'parents':folder_id
}
Hope this will help somenone who uses Google Drive API for the first time.
Fabio