5

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!

Michael
  • 439
  • 1
  • 4
  • 15
  • The answer from s.abbaasi in [this question](https://stackoverflow.com/questions/60739653/gdown-is-giving-permission-error-for-particular-file-although-it-is-opening-up-f) worked for me. – André Feb 26 '22 at 12:27

2 Answers2

14

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
korakot
  • 37,818
  • 16
  • 123
  • 144
  • Thanks! How do you do it for a folder? – Aman Bagrecha Aug 12 '21 at 18:16
  • @AmanBagrecha try to copy folder from drive to `content` and zip it. Then you can download it. for example there is a folder named `test`: ` `!cp -r /content/drive/MyDrive/FERET ./` `!zip -r 'test.zip' 'test'` – s.abbaasi Dec 21 '22 at 16:52
  • gdown works! I zipped the folder and then stored it on google drive. Then I downloaded the zipped folder using gdown onto google colab and unzipped there. – simpleParadox Mar 28 '23 at 22:33
5

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")