Thursday, October 18, 2018

How to download files from Google Drive to Google Colaboratory

How to download files from Google Drive to Google Colaboratory


Colaboratory is a research tool for machine learning education and research. It’s a Jupyter notebook environment that requires no setup to use. More info here.


 Navigate to https://colab.research.google.com and open a notebook.
Open File > New Python2 Notebook


How to download a file from google drive to Colaboratory 


from google.colab import auth
auth.authenticate_user()

from googleapiclient.discovery import build
drive_service = build('drive', 'v3')


import io
from googleapiclient.http import MediaIoBaseDownload

file_id = '1uIafI8_GgJSB-XgVa9_lHhJ3JunhT6GH'
request = drive_service.files().get_media(fileId=file_id)
downloaded = io.BytesIO()
downloader = MediaIoBaseDownload(downloaded, request)
done = False
while done is False:
  # _ is a placeholder for a progress object that we ignore.
  # (Our file is small, so we skip reporting progress.)
  _, done = downloader.next_chunk()
 
downloaded.seek(0)
print 'Downloaded file contents are:', downloaded.read()
downloaded.



How to download folder 

 this will throw error "HttpError: "

One option is to zip the folder and get file id of the archive.

file_id = '1VcwmEBcIEEFgYJVM1IT9ZmPI-SqSQEWe'
request = drive_service.files().get_media(fileId=file_id)
downloaded = io.BytesIO()
downloader = MediaIoBaseDownload(downloaded, request)
done = False
while done is False:
  # _ is a placeholder for a progress object that we ignore.
  # (Our file is small, so we skip reporting progress.)
  _, done = downloader.next_chunk()

print 'Download complete' 


downloaded

1 comment:

taversfabri said...

Play Blackjack for real money at the MGM National Harbor
You can play Blackjack on a wide 시흥 출장샵 variety of card 충주 출장안마 tables, including the $5 minimum bet that 하남 출장마사지 you can wager 남양주 출장안마 at the 이천 출장마사지 MGM National Harbor.