How to upload files larger than 1Mb to Colab

How to upload very large files over 1mb to google colab

I am going to explain 2 methods to upload large files to COLAB. And it is that there is a problem in Google Colab, or perhaps it is a restriction, that does not allow uploading files larger than 1Mb using its graphical interface.

It is very useful for those who are going to work with Whisper, since any audio weighs more than 1 MB

When uploading a file, it starts to load, it takes a long time and in the end the upload disappears or only 1Mb of our file is uploaded, leaving it incomplete.

I leave you a video

To solve this I will explain 2 methods:

  1. Importing files from Google Drive
  2. With the files library

As well I leave you a Colab with the code so you can see it and try it live

Import files to Colab from Google Drive

Another option to work with large files in Colab is to upload them to our Google Drive and sync Colab with Drive, so we can use whatever files we have there.

A very interesting option, especially when we have to use a Notebook on a recurring basis. We must remember that every time we run a notebook, all the information on the virtual hard disk is lost. Therefore having the notebook connected to Drive

IMPORTANT: That the email of the Colab account and the Google Drive account is the same, when I have tried to change it, using a Colab account and another Driva account, it has given me problems, although in theory it should work fine.

For this we will use the following code

from google.colab import drive
drive.mount('/content/drive')

Drive will ask us for permissions from the account

How to sync google drive with colab

Once accepted we will see that it mounts the hard drive and we can now see the files

Google drive for desktop permissions

And later

google drive permissions for google colab

They will be in a folder called drive or mydrive, in our case inside content as we have indicated

where to find google drive files in collaboration

You can update the content in the left bar, with the folder icon.

How to upload files to Colab with files

Very simple, we will only add 2 cells with the following code, it could all be done in one cell but I like having the one that allows us to select our file in an individual cell.

So at the beginning of our Colab we will use

from google.colab import files

to import that python library

And then in the step that we want to upload our file we will put

files.upload()

This will go up to the root of the Colab.

If you know any other way, leave a comment.

If you are a restless person like us and want to collaborate in the maintenance and improvement of the project, you can make a donation. All the money will go to buy books and materials to experiment and do tutorials

Leave a comment