Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Drive API - List Multiple Mime Types

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 300
Nick Avatar asked Dec 06 '12 03:12

Nick


People also ask

How do I find MIME type files?

For detecting MIME-types, use the aptly named "mimetype" command. It has a number of options for formatting the output, it even has an option for backward compatibility to "file". But most of all, it accepts input not only as file, but also via stdin/pipe, so you can avoid temporary files when processing streams.

How many MIME types are there?

There are 2868 known MIME types.

Where is MIME type stored?

All MIME type information is stored in a database. The MIME database is located in the directory /usr/share/mime/ . The MIME database contains a large number of common MIME types, stored in the file /usr/share/mime/packages/freedesktop. org.

What is MIME type mapping?

A file's MIME type specifies how a server or browser should interpret the file. For example, whether the file contains plain text, formatted HTML, an image, or a sound recording. In a Web server, MIME mappings specify how a static file should be interpreted by mapping file extensions to MIME types.


2 Answers

Yes you can, like this:

(mimeType = 'audio/mpeg' or mimeType = 'audio/mpeg3' or mimeType = 'audio/mp3')
like image 93
costa Avatar answered Oct 06 '22 16:10

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 38
user1828559 Avatar answered Oct 06 '22 18:10

user1828559