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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With