How to upload the file and read Google Colab

## Introduction
In a nutshell, Google Colaboratory is a free cloud service allowing us to play with GPU easily.
In this article, I would like to leave the basic usage of google colab(shorthand for google colaboratory) to other good entries below.

## References for Introduction to Google Colaboratory
https://medium.com/deep-learning-turkey/google-colab-free-gpu-tutorial-e113627b9f5d
https://www.codexa.net/how-to-use-google-colaboratory/

Instead, I would like to talk about the difficulty which I have found while following the instructions.

<font color="red"> Please use your target file to try the script in this entry </font color>

## Easiest way to do
You can just upload the zipped files from the notebook directly 

```python
from google.colab import files
uploaded = files.upload()
```

then unzip your files

```python
!unzip yourfile
```

this is the easiest way to do!lol


## How to upload the data onto the accessible directory from colab?
<img width="1114" alt="Screen Shot 2018-05-13 at 9.28.03.png" src="https://qiita-image-store.s3.amazonaws.com/0/240801/f7da278f-6d96-9430-a1d2-71a5b21e25c7.png">

For simplicity, let this be my current directory, and we want to read the text file from this **ptb.valid.txt** from Untitled0.ipynb.

Firstly, you open Untitled0.ipynb.
<img width="1440" alt="Screen Shot 2018-05-13 at 9.28.12.png" src="https://qiita-image-store.s3.amazonaws.com/0/240801/7650e5e9-a0b6-0efb-80c8-061430361d77.png">

Then you will see this jupyter notebook on your browser.
<img width="531" alt="Screen Shot 2018-05-13 at 10.32.58.png" src="https://qiita-image-store.s3.amazonaws.com/0/240801/5784e0d1-ad44-05aa-3804-965dba3a6fe0.png">


So, from now we are trying to access to our target file.
At this moment, if you try the code below, it will return "false", because you don't mount or even create the drive directory.

```python
import os
os.path.isfile("drive/Colab Notebooks/ptb.valid.txt")
```

So, let's create the folder named drive and mount it with your environment.
To mount it, you need a specific command called google-drive-ocamlfuse.
So let's get it executing scripts below.
I would like to mention that once i run this, I have got an error saying something weird,, sorry I didn't capture it though, when I run this again it went very well.
So don't give up by first error.

```bash
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}

# output will go like this..
install some stuff.
...
Please, open the following URL in a web browser: https://accounts.google.com/o/oauth2/auth?client_id=......
```
Wow,,, output is quite long and takes time to finish though, in the end you will be told to confirm the authentication of this access. So, following the order saying open the link, and you will visit some blue-ish page displaying your key. * I am not feeling comfortable to put that picture here..

Then try this command!

```python
os.path.isfile("drive/Colab Notebooks/ptb.valid.txt")

# output
false
```
Ups...
We haven't finished creating or mounting anything yet.
So try this.

```bash
!mkdir drive
!google-drive-ocamlfuse drive
!ls drive/"Colab Notebooks"
# output
Test_20180513.ipynb Untitled0.ipynb ptb.valid.txt
```
Congrats, now you have mounted your directory with your environment.
Finally we can read/write the file from our jupyter notebook!!

```python
f = open("drive/Colab Notebooks/ptb.valid.txt")
print(f.read(10))
# output
consumers
```

Thank you for reading.

## References
how to upload local files on google colab
https://stackoverflow.com/questions/47320052/load-local-data-files-to-colaboratory
official tutorial: https://colab.research.google.com/notebook#fileId=/v2/external/notebooks/io.ipynb
google colab in japanese: https://qiita.com/tomo_makes/items/f70fe48c428d3a61e131