Is it possible to use the Google Drive API to get file from within a shared .zip file

Viewed 296

Assume the following .zip file:

unzip -l myarchive.zip 
Archive:  myarchive.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
     3663  1980-00-00 00:00   sub_dir1/file1.txt
     4573  1980-00-00 00:00   sub_dir1/file2.txt
     6021  1980-00-00 00:00   sub_dir2/file1.txt
     6627  1980-00-00 00:00   file1.txt

The following command extracts the file sub_dir1/file1.txt from the .zip file when it is in the file system.

unzip -p myarchive.zip sub_dir1/file1.txt > file1.txt

But if the .zip file is in Google Drive with a shared link (e.g. the fileId is: 1234567...v4rzj),

Is it possible to make a Google Drive API query to get a specific file (e.g. sub_dir1/file1.txt) from within a .zip file?

1 Answers

Google drive is simply a file storage system it in and of itself it does not have the ability to unzip files in this manner or to check the contents of a file. The google drive api just gives you the ability to Create, update ,delete upload and download the files.

Other options.

as your unzip command works on a file stored locally on your machine. You will need to download the file from Google drive first and then run your unzip.

As you have not mentioned which programming language you are intending to use i recommend checking the documentation for examples.

This is an example using Java, you will need the authorization code as well.

String fileId = "0BwwA4oUTeiV1UVNwOHItT0xfa2M";
OutputStream outputStream = new ByteArrayOutputStream();
driveService.files().get(fileId)
    .executeMediaAndDownloadTo(outputStream);
Related