通过“完整路径"查找文件的正确方法是什么?在 Google Drive API v2 中 [英] What's the right way to find files by "full path" in Google Drive API v2

查看:19
本文介绍了通过“完整路径"查找文件的正确方法是什么?在 Google Drive API v2 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的

我正在尝试按完整路径"查找文档列表.并且在阅读 API 参考之后,这似乎是一项复杂的任务.假设我的路径类似于/path0/path1/path2/...

I'm trying to find a list of documents by "full path". And after reading the API reference, it seems to be a complex task. Assume my path is something like /path0/path1/path2/...

  1. 列出根文件夹的子文件夹并找到名称等于path0"的所有子文件夹并将它们放入列表result0"
  2. 查找result0"中名称等于path1"的所有子项并将它们放入列表result1"
  3. 查找result1"中名称等于path2"且...的所有子项...

上述方法似乎效率很低,因为它需要我的应用程序和 Drive 之间的多次交互.我了解 Google Drive 允许多个文件共享相同的文件名,即使在同一个文件夹中也是如此.如果我能做这样的事情会很方便:

Above approach seems very low efficient cause it needs multiple interactions between my application and Drive. I understand Google Drive allows multiple files share the same file name even in the same folder. It will be handy if I can do something like:

listDocByFullPath("path0/path1/path2")

当前版本的 Google Drive SDK 可以做到这一点吗?如果还没有,我想知道是否有比我在这里列出的更简单的方法.

Is this possible with current version of Google Drive SDK? If it's not there yet, I was wondering if there is a simpler way than what I listed here.

顺便说一句,由于我的应用程序纯粹是一个后端服务,所以无法使用谷歌提供的文件选择器.

BTW, as my application is purely a back-end service, it's not possible to use file picker provided by Google.

干杯.

推荐答案

与传统文件系统不同,一个文件可以位于云端硬盘的多个文件夹下.文件夹与标签非常相似.因此,常规路径并不总是在我们的抽象中起作用.我建议您遵循以下逻辑:

Unlike conventional file systems, a file could be under multiple folders on Drive. Folders are pretty much similar what labels are. Therefore, conventional paths dont always work within our abstraction. I'd suggest you to follow the logic below:

  1. 列出父项中 q = 'root' 且 title = 'path0' 和 mimeType = 'application/vnd.google-apps.folder' 的文件,然后选择第一个结果.
  2. 如果有匹配的结果,获取文件夹的id,并用'<id of path0>'执行另一个listing在 parents 和 title = 'path1' 和 mimeType='application/vnd.google-apps.folder' 中选择第一个结果.
  3. 继续前进,直到到达目标文件夹.
  1. List files with q = 'root' in parents and title = 'path0' and mimeType = 'application/vnd.google-apps.folder' and pick the first result.
  2. If there is a matching result, get the folder's id and perform another listing with '<id of path0>' in parents and title = 'path1' and mimeType='application/vnd.google-apps.folder' and pick the first result.
  3. Keep going until you reach to your target folder.

这篇关于通过“完整路径"查找文件的正确方法是什么?在 Google Drive API v2 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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