I made a fixed point camera with Raspberry PI, so this is the first memorandum. I also made a video, so thank you!
Basically, the services are as follows.
It is like a huge folder in the cloud provided by Google, and it is a service that allows you to easily write and read files. There is a free price, but you will be charged for reading, writing, and existing data size.
** Cloud side settings **
Log in to Google Cloud Platform and click Storage
> Browser
next to it.
Click Create Bucket
on the page that appears.
Create a bucket like this. The bucket name is free.
Once created, create a service account to access.
From the menu on the left, click ʻIAM & Administration>
Service Account`.
Click Create Service Account
at the top of the screen
The name is appropriate. Make it easy to understand.
Service account permissions
grants Cloud Storage permissions.
Keep as Cloud Storage
> Storage Administrator
in the role
Finally click Create Key
You can download it by clicking Create
with the JSON
type selected.
Please keep this file in a safe place for later use.
Also, please be aware that if this information becomes public, you will be billed in large numbers.
** Confirmed locally **
We will build a Python environment.
This time, in order to use python3
, enter the environment with the following command.
sudo apt install python3 python3-pip
After the installation is complete, install the python module google-cloud-storage
to access Cloud Storage.
pip3 install google-cloud-storage
Then write the code for testing. Please create the following code with nano etc.
#When making with nano
nano file2gs.py
file2gs.py
# /home/pi/image.Trial code to upload jpg
from google.cloud import storage
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="/home/pi/gkey.json"
client = storage.Client()
bucket = client.get_bucket('{Bucket name}')
blob2 = bucket.blob('test.txt')
blob2.upload_from_filename(filename='/home/pi/test.txt')
Before running, open the json file you downloaded earlier, copy it and write it to a file called gkey.json
.
#When making with nano
nano gkey.json
Copy the contents to the opened file. Also, create a file to upload.
echo "hi. this is text file">test.txt
In this state, enter the following command and execute it.
python3 file2gs.py
You can also check the contents by clicking the link below. Rest assured that it will not be published to the world by default ...
You have now uploaded your data to the cloud.