Download any files directly to the google drive. It uses Google Colab to download files. If you need to save the files from some website to drive then you have to download it and then uplaod it. This becomes very difficult when the file size is too large. This method solves the issue by directly downloading the file to drive, also at very high speed.
- Open Google Colab.
- Create a new notebook.
- Connect to the Drive and create a mount point. For that, authentication is required.
For authentication, choose an account to link then allow access to the Drive. It will generate the auth key, which needs to be entered in the Colab notebook.
from google.colab import drive drive.mount('/content/drive', force_remount = True)
- Use Linux bash commands to create a folder in our Drive. Colab or Jupyter notebook can run all the bash commands directly through the notebook. The below code will create a folder "Download" in the root directory of Drive. Remember not to change "My Drive", it is the root directory of Google Drive.
!mkdir "/content/drive/My Drive/Download"
- Use wget command to download the file to Download folder.
general syntax to download:
!wget -O '/content/drive/My Drive/Download/img1.jpg' "https://unsplash.com/photos/u159a2eL6UE/download?force=true"
where!wget -O '/content/drive/My Drive/Download/file_name.ext' "download_url"
file_name.ext
is the required name of the file and .ext represent the respective extention. Example:and replaceImg.jpg my_pic.png software.exe my_collection.zip
download_url
with the url of the file.
Note: If you can get a download link, which is in most of the cases, you will able to download the file. But sometime it may be challenging to get the download link.
In this repo, find downloader.ipynb
as an example notebook. You can check more details of wget
command here.