Google Drive Files API to get ALL files in a folder – even those that are marked as BINARY

  Kiến thức lập trình

I have 3 files in a Shared Drive in a folder – all of these are the same text file/data

  1. Uploaded the first one “abc123” and Drive treats it as a “Binary File”
  2. Made a copy of “abc123” in the same Drive Folder and renamed it to “xyz123.txt” and Drive still treats it as a “Binary File”
  3. On my local system – made a copy of the same file and renamed to “def123.txt” and uploaded it to this folder – notice Drive is treating it as a text file – MIME Type = text/plain

Folder Screenshot

Notice that the icons are different – Binary Files are a darker blue than the Text File

When using the Files API – https://developers.google.com/drive/api/guides/search-files – Here is the simple query

"1B8sn6MYwJdv6pnBYVxMltL7xHv2gwrf8" in parents and trashed = false

Where the ID above is for the Folder

I am expecting to get 3 files back – but only get the file type with a mimeType text/plain returned back

[
  {
      'driveId' => '0ABOnA8vd3emBUk9PVA',
      'id' => '1VmwioaAXtRJgErh6321K5pnvdzt-8dWO',
      'kind' => 'drive#file',
      'mimeType' => 'text/plain',
      'name' => 'def123.txt',
      'teamDriveId' => '0ABOnF8vd3emBUk9PVA'
   }
 ]

How can the files “abc123” and “xyz123.txt” – which Drive considers both Binary Files – be included in the results by the Google Drive Files API when querying for a list of files??

I have tried to make the query more specific by adding the mimeType for Binary files but this does not seem to work.

"1B8sn6MYwJdv6pnBYVxMltL7xHv2gwrf8" in parents 
and mimeType = "BINARY-MIME-TYPE-HERE" 
and trashed = false

I have tried all of these without success

  • application/octet-stream
  • application/octetstream
  • binary/octet-stream
  • application/binary
  • application/x-binary
  • octet/stream

New contributor

Bill Hess is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT