1

I have the shared link of a Google Drive folder. I want to download the entire folder using the drive API. The way I am doing this currently is that I get a list of 'children' and then download all the 'children' instances into the folder. The problem is that for each 'children' instance download, a request is sent to googleapis. So, if there are a 1000 files, 1000 requests are sent. I have a folder with more than 10M small files and Google limits the number of requests to 10M per day. I wanted to know if there is some way(any function in drive api) to download the entire folder at once? Here is my code:

storage = Storage(CredentialsModel, 'id', task_request.user, 'credential')
credential = storage.get()
http = httplib2.Http()
http = credential.authorize(http)
service = build('drive', 'v2', http=http)

file_list = []
children = service.children().list(folderId=folder_id, q=q, **param).execute()
for child in children.get('items', []):
    file_list.append(child['id'])

for k in range(len(file_list)):
    curr_file = service.files().get(fileId=file_list[k]).execute()
    download_url = curr_file.get('downloadUrl')
    if download_url:
        resp, content = service._http.request(download_url)

    if resp.status == 200:
        title = drive_file.get('title')
        path = title
        file = open(path, 'wb')
        file.write(content)
manky1304
  • 31
  • 3
  • Not that I know of, but it seems a reasonable enhancement request. You could also ping Google directly to see if the limit could be raised for your app. Depending on how small the files are, you might also want to reconsider your architecture. Storing the files as data in a spreadsheet or fusion table might be a better fit. – pinoyyid May 20 '15 at 11:14
  • @pinoyyid the files are image files! – manky1304 May 20 '15 at 12:16
  • here is a trick that might work: drive image files might be viewable as a google+ album and g+ has a way to download an entire album as a zip. thou its manual (no api) and ixdont know how to make the picture in drive be in plus (the other way arround does happen) – Zig Mandel May 20 '15 at 13:46
  • Ok! Following on from Zig's suggestion, you could also look at the Picasa API which might offer something similar (a guess) – pinoyyid May 20 '15 at 14:27

0 Answers0