TypeError: Cannot read property '_uploadFiles' of undefined in google colaboratory

Question:

I am trying to write upload the file in Google Colaboratory and I’m going to write the code as below.

from google.colab import files
uploaded = files.upload()

But I am getting the below error to run the code in browser.

MessageError: TypeError: Cannot read property ‘_uploadFiles’ of undefined

Please help me solve the issue.

Answers:

I just tried the code snippet:

from google.colab import files
uploaded = files.upload()

and everything worked as I’d expect.

A typical cause of the error you observe is using an unsupported browser or a browser extension. Try disabling extensions. Or, if you are using a browser other than Firefox, Safari, or Chrome, try one of these.

Answered By: Bob Smith

I am having the same issue. It fails when called from inside a function. The code that fails is here

from google.colab import files

def f(fname):
    x = files.upload()
    return x[fname]
f('hello')

It works fine when I call files.upload() directly(top-level). It only fails when called from inside a function

Answered By: Sunil S Nandihalli

I had the same error as yours when running the code in Colaboratory in Brave Browser. However, after switching to Google Chrome, it ran just fine. So check the browser you’re running in and try another one (I tried Microsoft Edge and it didn’t work, btw)

Answered By: Jared Hasson

The problem is being caused due to two things: 1.file.upload() opens up a widget. passing it to the variable somehow is not waiting for the file to be loaded. Its returning – ‘MessageError: TypeError: Cannot read property ‘_uploadFiles’ of undefined’;2. the other is – this functionality seems to be working for only google chrome as of now else, it will require quite adjusting cookies as suggested in other answers. It is very time consuming unless you have done something like this before.

instead use:

files.upload()

once the files are upload, say like ‘train.csv’. It can be loaded as

import pandas as pd
train = pd.read_csv(‘train.csv’)

Answered By: Muralidharan M

In order to upload the file "YOURFILE.csv" in your directory ‘YOURDIRECTORY’, You can upload the directory into google drive, and do the following.

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

Then if you see the content of your current directory, you see the "My Drive" which is your google drive and now you can have access to the files saved in your google drive.
!ls command shows you the current directory content.

Now you can import your file into the current colab:

your_data = pd.read_csv("./My Drive/YOURDIRECTORY/YOURFILE.csv")
Answered By: Mehdi Rostami

I was having the same problem a minute ago and, although I was not able to catch the error, there is an alternative to the file uploading method you are using.

You can just upload your file in Colab by clicking the folder icon at the notebook’s sidebar and then clicking the upload button.

To load your file into a cell, for example a csv file, you can just write (if you are using pandas):

df = pd.read_csv('path_to/my_file.csv')

this should be browser agnostic.

Answered By: ihojmanb

Well, if running on Brave Browser, i can confirm that turning down the shields will do the job.

Answered By: Shiva Govindaswamy

You may be using an ad blocker, or possibly an ad-blocking site such as Brave browser, or something that blocks cross-site cookies!

If that is the case, try to disable that and it will work fine 🙂

Answered By: Kasra

Navigate to chrome://settings/content/cookies and turn off “block third-party cookies”.
It works for me!

Answered By: Cuong Trinh

The alternate solution would be:

  1. Mount your google drive
  2. Save your folder from your location machine in google drive
  3. Then from the drive copy the path of the file which you need to read
df = pd.read_csv("paste the path you copied here")

I hope this works

Answered By: CHETAN Desai

I also faced the same problem in google colaboratory as I am using it in incognito mode.

third-party cookies blocked

You have to allow cookies.

  • click the third-party blocking icon
  • click Site not working?
  • Allow cookies

third-party cookies unblocked

Here is a sample code that you can check for file uploading. First, mount the drive.

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

Then use this for uploading files from your local file system.

from google.colab import files

uploaded = files.upload()

for filename in uploaded.keys():
    print(uploaded[filename])

I hope this will solve your problem.

Answered By: Badhan Sen

Try restarting google chrome, or if that doesn’t work, try restarting your computer, that tends to fix any local library issues that my be there.

Answered By: Rafey Iqbal Rahman

go to browser settings –> search cookies –> Cookies and other site data

enter image description here

enter image description here

Click on allow all cookies then refresh it.
I didn’t change any code and I am able to upload the file after the browser changes.

Answered By: Rakesh

I had this same problem on Chromium. I switched to Firefox and everything worked fine.

Answered By: tyler hanson

I think you have already got your answer. On top of that if you are using chrome’s incognito mode, there are chances of getting this type error. Try with normal chrome browser.

Answered By: Somanna Kuri

The reason is blocked third-party cookies.

What you can do is,
Navigate to chrome://settings/cookies

In the below you will see a section called, Sites that can always use cookies

Click on Add and add [*.]googleusercontent.com

enter image description here

Now it works

Answered By: Randula Koralage

enter image description here

If you are using Microsoft Edge as a browser go to the following page "edge://settings/privacy" and use the normal mode for tracking protection.
This should solve the problem of accessing the files.

Answered By: JEAN VIVIEN AKOU

in Brave Browser, follow these instructions:

go to

Settings → Shields, and
enter image description here

Answered By: Steele Rocky

Allow all cookies to fix this error message.

Steps to fix /typeerror-cannot-read-property-uploadfiles-of-undefined-in-google-colaboratory

Settings->Privacy and security->Cookies and other site data->Allow all cookies(select it)

brave settings

Answered By: devp
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.