Is there a way to download data from a public link to google colab?

Viewed 9475

I am currently working with a Jupyter file on google colab with 5000 images and several csv files. I wish to find a way to download these data into the colab from a shareable link from google drive without mount to drive, which is: I upload these data into drive first and make them "anyone can view with link", and then I wish to find a way to download these data into colab with this link (So that others can simply run my code without authorization or mount to drive)

Is there any way I can achieve this? Thank you!

2 Answers

You can use gdown.

For example, an image url

https://drive.google.com/file/d/1ztBz3C_2BlXgNGK2mbarGnVqoI287_XT/view?usp=sharing

It's id = 1ztBz3C_2BlXgNGK2mbarGnVqoI287_XT

So, you can download it with

!gdown --id 1ztBz3C_2BlXgNGK2mbarGnVqoI287_XT

you can use !wget in colab to download .csv file in your runtime storage For Example this is public link for google sheet https://docs.google.com/spreadsheets/d/FILE_ID/edit?usp=sharing

we need to get download url for this google sheet file follow link to get download link

Creating a link to download whole spreadsheet from Google Drive

now we got download url in this form https://docs.google.com/spreadsheets/d/FILE_ID/export?

type this code in colab !wget https://docs.google.com/spreadsheets/d/FILE_ID/export? file will be downloaded like this snap shot from colab

rename file as your choice rename snapshot

finally import it using df = pd.read_csv("/content/file.csv")

Related