I have tried downloading small files from google Colaboratory. They are easily downloaded but whenever I try to download files which have a large sizes it shows an error? What is the way to download large files?
Asked
Active
Viewed 1.2k times
4 Answers
17
If you have created a large zip file, say my_archive.zip, then you can download it as following:
- Mount your Google drive from your Google colab Notebook. You will be asked to enter a authentication code.
from google.colab import drive
drive.mount('/content/gdrive',force_remount=True)
- Copy the zip file to any of your google drive folder (e.g. downloads folder). You may also copy the file on 'My Drive' which is a root folder.
!cp my_archive.zip '/content/gdrive/My Drive/downloads/'
!ls -lt '/content/gdrive/My Drive/downloads/'
Finally, you can download the zip file from your Google drive to your local machine.

codefun
- 316
- 2
- 6
11
This is how I handle this issue:
from google.colab import auth
from googleapiclient.http import MediaFileUpload
from googleapiclient.discovery import build
auth.authenticate_user()
Then click on the link, authorize Google Drive and paste the code in the notebook.
drive_service = build('drive', 'v3')
def save_file_to_drive(name, path):
file_metadata = {
'name': name,
'mimeType': 'application/octet-stream'
}
media = MediaFileUpload(path,
mimetype='application/octet-stream',
resumable=True)
created = drive_service.files().create(body=file_metadata,
media_body=media,
fields='id').execute()
print('File ID: {}'.format(created.get('id')))
return created
Then:
save_file_to_drive(destination_name, path_to_file)
This will save whatever files to your Google Drive, where you can download or sync them or whatever.

Eric Antoine Scuccimarra
- 375
- 2
- 7
-
this gives me an error: media = MediaFileUpload(path, ^ IndentationError: unexpected indent – Stepan Yakovenko Aug 18 '18 at 16:36
-
Try putting it all on one line: media = MediaFileUpload(path, mimetype='application/octet-stream', resumable=True) – Eric Antoine Scuccimarra Aug 20 '18 at 09:20
-
what is the path_to_file? Is it a drive link or just an explicit path such as MyDrive/ models? @EricAntoineScuccimarra – 96var3 Oct 17 '18 at 03:04
-
path_to_file is the name you want to save the file as in Drive. If you can specify subdirectories I haven't been able to figure out how yet. – Eric Antoine Scuccimarra Oct 23 '18 at 15:47
1
I tried many different solutions. The only way that was effective and quick is to zip the file/folder and then download it directly:
!zip -r model.zip model.pkl
And to download:

Minions
- 5,104
- 5
- 50
- 91
0
Google colab doesn't allow you to download large files using files.download()
. But you can use one of the following methods to access it:
- The easiest one is to use github to commit and push your files and then clone it to your local machine.
- You can mount google-drive to your colab instance and write the files there.

Ankur Ankan
- 2,953
- 2
- 23
- 38
-
1when I run the command - !git push -u origin master It asks for my username and password. How ca I enter my username and password in the current running cell? Can not see a space where I can enter them. – shivin saluja Mar 30 '18 at 13:54
-
@shivinsaluja You can't enter username and password. You will need to setup access to github using ssh: https://help.github.com/articles/connecting-to-github-with-ssh/ – Ankur Ankan Mar 30 '18 at 18:45
-
you cant do it also because sshj-keygen wants keyboard interaction – Stepan Yakovenko Aug 18 '18 at 16:37