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

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

问题描述

亲爱的所有人



我试图通过完整路径找到文档列表。阅读API参考后,它似乎是一项复杂的任务。假设我的路径类似于/ path0 / path1 / path2 /...


  1. 列出根文件夹的子项并查找名称为equals的所有子项path0并将它们放到result0列表中

  2. 查找名为path1的result0中的所有子项并将它们放到列表result1中

  3. 查找result1中所有项目的子项名称等于path2和...

上述方法似乎效率很低,因为它需要我的应用程序和驱动器之间的多种交互。我了解Google Drive允许多个文件共享相同的文件名,即使在同一个文件夹中。如果我可以这样做,它会很方便:

  listDocByFullPath(path0 / path1 / path2)

目前版本的Google云端硬盘SDK有这种可能吗?如果还不存在,我想知道是否有比我在这里列出的更简单的方法。

顺便说一句,因为我的应用程序纯粹是一个后端服务,它无法使用Google提供的文件选择器。



干杯。

解决方案

<与传统文件系统不同,文件可能位于云端硬盘上的多个文件夹下。文件夹与标签非常相似。因此,传统路径并不总是在我们的抽象中工作。我建议你按照下面的逻辑:


  1. 列出父母中含有q = 'root'的文件, title ='path0'和mimeType ='application / vnd.google-apps.folder'并选取第一个结果。 如果有匹配的结果,获取文件夹的ID并在父母和标题='path1'和mimeType ='application / vnd.google-apps.folder''< id of path0>'选择第一个结果。

  2. 继续操作,直到到达目标文件夹。


dear all

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. List children of root folder and find all children with name equals "path0" and put them to a list "result0"
  2. Find all children of items in "result0" with name equals "path1" and put them to a list "result1"
  3. Find all children of items in "result1" with name equals "path2" and ...

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

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.

Cheers.

解决方案

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. 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天全站免登陆