Hi readers,
If you are here I assume you have some files in your onedrive storage and you want to access that from google colab without the hassle of downloading and uploading over and over.
You are exactly where you need to be. Let me brief you quickly as to what we are gonna do through this blog and then we will get right to the steps because I am sure you have been searching for quite some time for this.
Contents:
- Downloading Rclone software
- Authorizing Rclone to your onedrive account from local
- Generate config token on the local system
- Use generated token to authorize google colab
- Final mount and access files
Now, that I have given an outline of what will be done throughout the blog, let's get to the steps without further delay.
Step 1:
Firstly download the rclone software on your local system from here based on your system specifications.
Make sure to download the latest version at the time you are reading this blog.
Step 2:
After step 1, the rclone software will be downloaded in the form of a zip file.
Extract the contents of the zip and move inside the extracted directory. It should contain one application file named rclone with some more files.
Now within that directory open the command line and type in the following.
rclone authorize "onedrive"
This will open a tab in your default browser and ask you to login into your onedrive account. Login using your credentials. After successful login, it will show the below message.
In case you are already logged in to your account then you will see the above message directly.
Once you see the success message, close the browser and come back to your command line. Now you should see an access token given in the command line in the following format:
{"access_token": "EwBsdkjfdibdnndsnd......................."}
The token will be quite long. Just copy it. Let's move on to setting this token to generate another one. 😀
Step 3:
Next in the same command line type in the below command:
rclone config
Now it will give you options to create or update remote connections Use the commands as shown in the images below.
After following the steps exactly as shown in the image, it should be asking for the config token. In here paste the token that you copied earlier in step 2.
After that, it will ask the type of drive and select 1 (onedrive) from there and after that, it will search for the remote onedrive account, next click on enter twice to confirm the found account.
After that, it will generate another token and give the option to exit the config environment.
Copy the newly generated token and exit using the "q" command.
Step 4:
Now we are ready to move to google colab and configure the same inside a notebook using the token you copied last.
Open a new notebook and type in the commands in the first cell.
!wget https://downloads.rclone.org/v1.57.0/rclone-v1.57.0-linux-amd64.deb
!apt install ./rclone-v1.57.0-linux-amd64.deb
This will download the rclone software using the google colab notebook and install the software.
Note: In this case, I used version 1.57.0, but in your case update the command accordingly for the version of rclone you downloaded in your system. Otherwise, the token might not be compatible.
Once the above steps run, you will see the rclone software in your file section. Next, run the following command in another cell:
!rclone config
After these follow the same steps as in step 3 for this command and for the config token paste the token copied from your local terminal at the end of step 3.
Complete all the steps successfully and then in a new cell type in:
!sudo mkdir /content/onedrive
!nohup rclone --vfs-cache-mode writes mount onedrive: /content/onedrive &
Once your run this command this will show the onedrive folder in your colab files section.
BAM
That's all you needed to do. Now you can read and write files from and to your onedrive account directly from google colab.
If you faced some error in some steps and are stuck there, comment down. I will help you out. I faced my share of those a lot.
Note: The token used to access the account expires after a certain time period. If that happens then repeat the steps from Step 2.
That's it from my side for this blog.
Now go back to your code. I know you have a lot pending because you were stuck with this problem.
I will see you around in some other blog working through some other problem. Thanks for reading.
Check more about my work here:
👍
ReplyDeleteThanks :)
DeleteThat's really understandable easily
ReplyDeleteThanks for the feedback
Delete