├── GDrive_using_GColab.ipynb └── README.md /GDrive_using_GColab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "GDrive using GColab.ipynb", 7 | "provenance": [] 8 | }, 9 | "kernelspec": { 10 | "name": "python3", 11 | "display_name": "Python 3" 12 | } 13 | }, 14 | "cells": [ 15 | { 16 | "cell_type": "code", 17 | "metadata": { 18 | "id": "ck7pMIEAlgxz", 19 | "colab_type": "code", 20 | "colab": {} 21 | }, 22 | "source": [ 23 | "from google.colab import drive\n", 24 | "drive.mount( '/content/gdrive' )" 25 | ], 26 | "execution_count": 0, 27 | "outputs": [] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "metadata": { 32 | "id": "9VMWiuommBbW", 33 | "colab_type": "code", 34 | "colab": {} 35 | }, 36 | "source": [ 37 | "import requests\n", 38 | "file_url = \"http://1.droppdf.com/files/5iHzx/automate-the-boring-stuff-with-python-2015-.pdf\"\n", 39 | "r = requests.get(file_url, stream = True)\n", 40 | "with open(\"/content/gdrive/My Drive/python\",\"wb\") as file:\n", 41 | " for block in r.iter_content(chunk_size = 1024):\n", 42 | " if block:\n", 43 | " file.write(block)" 44 | ], 45 | "execution_count": 0, 46 | "outputs": [] 47 | } 48 | ] 49 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | When we download/upload something from a cloud server, it gives more transfer rate as compared to a normal server. We can use Google Drive for storage as well as fast speed download. The problem is how to upload something to G-Drive direct from Internet. So, Here we will see a solution to upload anything to Google drive directly from Internet. 2 | 3 | All we need is google account and a few lines of code. 4 | 5 | [Colab Google](https://colab.research.google.com/notebooks/intro.ipynb) 6 | 7 | Google Colab is a free cloud service with GPU support. It is like Jupyter Notebook and very simple to use. In this tutorial, we will be using Google Colab to download anything to our google drive. 8 | 9 | **Step #1 : Sign in to Google Colab and Create a new Python3 notebook.** 10 | ![Atom](https://i.imgur.com/8Qu5ivW.png) 11 | 12 | ![Atom](https://i.imgur.com/QZzfIiJ.png) 13 | 14 | **Step #2 : Importing google drive to colab** 15 | 16 | To import google drive, write this code in code section of colab and run it by `Ctrl+Enter` . 17 | 18 | ``` 19 | from google.colab import drive 20 | drive.mount( '/content/gdrive' ) 21 | ``` 22 | 23 | ![Atom](https://i.imgur.com/vyNxcAO.png) 24 | 25 | ![Atom](https://i.imgur.com/ZVmz6jR.png) 26 | 27 | On running code, one blue link and a text box will appear we need to provide a permission text. So click the link and a new tab will open where you will be asked for permission to access google drive. After providing permissions a text will be displayed that we need to Copy and paste on colabs text box. 28 | 29 | ![Atom](https://i.imgur.com/yZbWnSh.png) 30 | 31 | Paste text in box and press enter. That all to import gdrive. We can see google drive on Left side Panel. 32 | 33 | ![Atom](https://i.imgur.com/whlXOFZ.png) 34 | 35 | **Step #3 : Download something to Google Drive** 36 | 37 | To download something all we need is URL to downloadable file. 38 | 39 | ``` 40 | import requests 41 | file_url = "http://1.droppdf.com/files/5iHzx/automate-the-boring-stuff-with-python-2015-.pdf" 42 | r = requests.get(file_url, stream = True) 43 | with open("/content/gdrive/My Drive/python.pdf","wb") as file: 44 | for block in r.iter_content(chunk_size = 1024): 45 | if block: 46 | file.write(block) 47 | ``` 48 | 49 | ![Atom](https://i.imgur.com/KQGMrKI.png) 50 | 51 | We can see on the left side panel that pdf file is downloaded. 52 | 53 | **Conclusion:** 54 | 55 | We can use google colab to download any file on google drive. 56 | 57 | As you can see a folder parrot (parrot OS of 3.7 GB ), downloaded to gdrive using Colab. 58 | 59 | Material source:Geeks for Geeks 60 | --------------------------------------------------------------------------------