Skip to content

Instantly share code, notes, and snippets.

@koji
Last active May 2, 2018 23:13
Show Gist options
  • Save koji/2383d2beb4cd5b14dbcc9a85cdc2163b to your computer and use it in GitHub Desktop.
Save koji/2383d2beb4cd5b14dbcc9a85cdc2163b to your computer and use it in GitHub Desktop.
Note for Colaboratory

file uploader

from google.colab import files
files.upload()

using google drive

install a library
!pip install -U -q PyDrive

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

# auth
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

share files and get id

id = 'file id'
downloaded = drive.CreateFile({'id': id})
downloaded.GetContentFile('input.jpg')

from IPython.display import Image
Image('input.jpg')

download file

from google.colab import files
files.download()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment