Reputation: 233
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.
Upvotes: 21
Views: 41262
Reputation: 176
I encountered this same thing randomly after resetting my session and trying to run all the cells. I had forgotten about a %%capture
statement at the top of the cell which seemed to cause problems. Removing that worked for me.
Upvotes: 0
Reputation:
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)
Upvotes: 0
Reputation: 651
in Brave Browser, follow these instructions:
go to
Settings → Shields, and
Upvotes: 0
Reputation: 11
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.
Upvotes: 1
Reputation: 348
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
Now it works
Upvotes: 3
Reputation: 1
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.
Upvotes: 0
Reputation: 737
I also faced the same problem in google colaboratory as I am using it in incognito mode.
You have to 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.
Upvotes: 6
Reputation: 139
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")
Upvotes: 3
Reputation: 1
I had this same problem on Chromium. I switched to Firefox and everything worked fine.
Upvotes: 0
Reputation: 21
go to browser settings --> search cookies --> Cookies and other site data
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.
Upvotes: 0
Reputation: 833
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 :)
Upvotes: 0
Reputation: 1
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.
Upvotes: 0
Reputation: 21
The alternate solution would be:
df = pd.read_csv("paste the path you copied here")
I hope this works
Upvotes: 0
Reputation: 347
Navigate to chrome://settings/content/cookies and turn off "block third-party cookies". It works for me!
Upvotes: 20
Reputation: 38674
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.
Upvotes: -9
Reputation: 719
Well, if running on Brave Browser, i can confirm that turning down the shields will do the job.
Upvotes: 33
Reputation: 482
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.
Upvotes: 0
Reputation: 27
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')
Upvotes: 1
Reputation: 377
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)
Upvotes: 1
Reputation: 57
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
Upvotes: 0