[GO] How to upload a file to Cloud Storage using Python [Make a fixed point camera with Raspberry PI # 1]

At first

I made a fixed point camera with Raspberry PI, so this is the first memorandum. I also made a video, so thank you! IMAGE ALT TEXT HERE

What to understand

Create

What to prepare

procedure

1. 1. Google Cloud Platform related

What is Google Cloud Platform (Google Cloud Storage)?

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. image.png

Click Create Bucket on the page that appears. image.png

Create a bucket like this. The bucket name is free. image.png image.png image.png

Once created, create a service account to access. From the menu on the left, click ʻIAM & Administration> Service Account`. image.png

Click Create Service Account at the top of the screen image.png

The name is appropriate. Make it easy to understand. image.png

Service account permissions grants Cloud Storage permissions. Keep as Cloud Storage> Storage Administrator in the role image.png

Finally click Create Key image.png

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. image.png

** 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

image.png

You can also check the contents by clicking the link below. Rest assured that it will not be published to the world by default ... image.png

You have now uploaded your data to the cloud.

Recommended Posts

How to upload a file to Cloud Storage using Python [Make a fixed point camera with Raspberry PI # 1]
How to upload files to Cloud Storage with Firebase's python SDK
How to make a surveillance camera (Security Camera) with Opencv and Python
Upload file to GCP's Cloud Storage (GCS) ~ Load with local Python
I tried to make a motion detection surveillance camera with OpenCV using a WEB camera with Raspberry Pi
How to read a CSV file with Python 2/3
How to use Raspberry Pi pie camera Python
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
How to make a Python package using VS Code
Connect Raspberry Pi to Alibaba Cloud IoT Platform with Python
Using a webcam with Raspberry Pi
File upload to Azure Storage (Python)
Control the motor with a motor driver using python on Raspberry Pi 3!
How to make a command to read the configuration file with pyramid
I tried to make a todo application using bottle with python
[Note] Using 16x2-digit character LCD (1602A) from Python with Raspberry Pi
[ROS2] How to play a bag file with python format launch
Upload files to Aspera that comes with IBM Cloud Object Storage (ICOS) using SDK (Python version)
[Python] How to make a class iterable
Make a wash-drying timer with a Raspberry Pi
Detect analog signals with A / D converter using python on Raspberry Pi 3!
[Python + PHP] Make a temperature / humidity / barometric pressure monitor with Raspberry Pi
How to upload with Heroku, Flask, Python, Git (4)
How to create a JSON file in Python
How to make a dictionary with a hierarchical structure.
I want to make a game with Python
[Python] How to read excel file with pandas
Try to make a "cryptanalysis" cipher with Python
Try to make a dihedral group with Python
How to upload to a shared drive using pydrive
I want to write to a file with Python
Connect to MySQL with Python on Raspberry Pi
How to drop Google Docs in one folder in a .txt file with python
WEB scraping with python and try to make a word cloud from reviews
Creating a temperature control system with Raspberry Pi and ESP32 (3) Recipient Python file
Convert the cURL API to a Python script (using IBM Cloud object storage)
How to make a Raspberry Pi that speaks the tweets of the specified user
How to convert / restore a string with [] in python
Create a color sensor using a Raspberry Pi and a camera
[Python] How to draw a line graph with Matplotlib
Try to make a command standby tool with python
Explain in detail how to make sounds with python
How to upload with Heroku, Flask, Python, Git (Part 3)
How to use the Raspberry Pi relay module Python
How to make a shooting game with toio (Part 1)
How to measure mp3 file playback time with python
How to convert JSON file to CSV file with Python Pandas
How to upload with Heroku, Flask, Python, Git (Part 1)
How to upload with Heroku, Flask, Python, Git (Part 2)
[Python] How to create a 2D histogram with Matplotlib
Output to "7-segment LED" using python on Raspberry Pi 3!
How to execute a command using subprocess in Python
A memorandum when making a surveillance camera with Raspberry Pi
Display USB camera video with Python OpenCV with Raspberry Pi
[Python] How to draw a scatter plot with Matplotlib
Make a note of what you want to do in the future with Raspberry Pi
It was great to edit the Python file in the Raspberry Pi with Atom's remote function
I want to make a voice changer using Python and SPTK with reference to a famous site
Update Python for Raspberry Pi to 3.7 or later with pyenv
[Python] How to make a list of character strings character by character
How to convert an array to a dictionary with Python [Application]