How to Download File From URL to Google Drive Using Google Colab in Python Full Project For Beginners

How to Download File From URL to Google Drive Using Google Colab in Python Full Project For Beginners




Welcome folks today in this post we will be talking about how to download any file from url in python using google colab to your google drive. All the source code regarding this project will be shown below.




Get Started



In order to get started you must be having a google account to use google colab feature.


Google Colab is a google technology online which allows you to execute python code inside your browser for free.


Now to get started you need to create a new workbook as shown in the figure. First go to Google Colab here.






Now you need to write some code inside this workbook. Just copy paste the code which is shown below.


from google.colab import drive




Here just copy paste the above code inside the google colab editor like this as shown below





Now if you run this code by pressing the triangle button which is there on left side you will see the following result which is shown below

See also  Python 3 Script to Convert Celsius to Fahrenheit Temperature Full Project For Beginners





Now you need to go to this above url and grant permissions to use google drive and then copy paste the authorization code inside this text field and then press enter











So you can see it has successfully mounted all my google drive files on the left hand side now we have the full access to do anything with our google drive such as upload any file, download any file to drive, remove files etc.



Now just write code to download file from url to drive using colab. Just copy paste the following code which is shown below



import requests 
r = requests.get(file_url, stream = True) 

with open("/content/gdrive/My Drive/python.pdf", "wb") as file: 
    for block in r.iter_content(chunk_size = 1024): 
        if block: 







Now you can see after executing this code a python.pdf has been successfully downloaded from the url and stored it inside our google drive.



Leave a Reply