Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list Multiple Mime types files From Google drive? [duplicate]

Is there a way to make one call to search for multiple mimeTypes at once? For example, I'm trying to find all mp3 files in a folder. It seems like you need to make a call for each individual mimeType to find all the different ones, similar to this:

https://www.googleapis.com/drive/v2/files?key=aaamykeyaaa&q=mimeType='audio/mpeg' https://www.googleapis.com/drive/v2/files?key=aaamykeyaaa&q=mimeType='audio/mpeg3' https://www.googleapis.com/drive/v2/files?key=aaamykeyaaa&q=mimeType='audio/mp3'

Is there no way to include multiple mimeTypes in one query? It's very inefficient to do it this way.

Thanks.

like image 546
Nick Avatar asked Nov 23 '22 17:11

Nick


2 Answers

Yes you can, like this:

(mimeType = 'audio/mpeg' or mimeType = 'audio/mpeg3' or mimeType = 'audio/mp3')
like image 182
costa Avatar answered Nov 26 '22 06:11

costa


The deprecated Documents List API has that where you just set "type:audio" in the query. I can't find something similar in the Drive API, but you can try using some undocumented search features:

  • use the contains operator for mimeType: mimeType contains 'audio/'
  • use the or operator: mimeType = 'audio/mpeg' or mimeType = 'audio/mp3' or ...
  • you can use other operators as well: mimeType > 'audio/' and mimeType < 'audio/~'

I think they are undocumented because they don't index well. If the user has lots of files, you might need to paginate through a lot of pages with empty items before you get results. You might also get more rate limiting errors if you try to query this way because it is taxing to their servers. It might be more efficient to query each mimeType separately. The Drive API should provide a new operator (like startswith) or a new parameter for these kinds of queries (similar to the Documents List API).

like image 40
user1828559 Avatar answered Nov 26 '22 08:11

user1828559