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.
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
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)
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’)
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")
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.
Well, if running on Brave Browser, i can confirm that turning down the shields will do the job.
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 🙂
Navigate to chrome://settings/content/cookies and turn off “block third-party cookies”.
It works for me!
The alternate solution would be:
- Mount your google drive
- Save your folder from your location machine in google drive
- 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
I also faced the same problem in google colaboratory as I am using it in incognito mode.
You have to allow cookies.
- click the third-party blocking icon
- click Site not working?
- Allow cookies
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.
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.
I had this same problem on Chromium. I switched to Firefox and everything worked fine.
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.
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.
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.
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.
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
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)
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’)
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")
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.
Well, if running on Brave Browser, i can confirm that turning down the shields will do the job.
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 🙂
Navigate to chrome://settings/content/cookies and turn off “block third-party cookies”.
It works for me!
The alternate solution would be:
- Mount your google drive
- Save your folder from your location machine in google drive
- 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
I also faced the same problem in google colaboratory as I am using it in incognito mode.
You have to allow cookies.
- click the third-party blocking icon
- click Site not working?
- Allow cookies
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.
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.
I had this same problem on Chromium. I switched to Firefox and everything worked fine.
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.
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.