Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file download from google drive to colaboratory

I was trying to download file from my google drive to colaboratory.

file_id = '1uBtlaggVyWshwcyP6kEI-y_W3P8D26sz'  import io from googleapiclient.http import MediaIoBaseDownload  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: {}'.format(downloaded.read())) 

doing so am getting this error:

NameError: name 'drive_service' is not defined 

How to remove this error?

like image 751
A Santosh Avatar asked Feb 11 '18 19:02

A Santosh


People also ask

How do you download a file from Google Drive to Colab?

Step #2 : Importing google drive to colab So click the link and a new tab will open where you will be asked for permission to access google drive. After providing permissions a text will be displayed that we need to Copy and paste on colabs text box. Paste text in box and press enter. That all to import gdrive.


1 Answers

No installing/importing any library. Just put your file id at the end.

!gdown --id yourFileIdHere 

Note: at the time of writing gdown library is preinstalled on colab.

like image 185
hoper Avatar answered Sep 21 '22 03:09

hoper