(click to expand or hide)
See more detail here
Estimated billing cost that's used in this projects:
Services | Price |
Cloud Run | IDR 0 |
Cloud Storage | IDR 33,502.95 |
Cloud Build | IDR 0 |
Firestore | IDR 11,187.07 |
Total | IDR 44,690.02 |
See more detail here
- Firebase project.
- Google Cloud Platform project and billing enabled.
Firebase:
- In the Firebase Console, click Add project to create a Firebase project.
- Click Authentication from the left hand menu. Select Sign-in method tab and click Add new provider. Add provider for Email/Password, Google, and Facebook.
- Select Users tab and click Add user to create a new user. Later this user will be used by the Cloud Computing team to generate tokens when testing REST API.
- Click Project Overview from the left hand menu. Then click Add application to register the Web Application. This app is used to generate tokens.
- Click Project settings next to Project Overview. Then select Service accounts tab and click Generate new private key. Save it as
serviceAccountKey.json
. - Still in the Project Settings, select Users and permissions tab and click Add member to add the Mobile Development team so they can register Android App Applications.
Google Cloud Platform:
-
In the Google Cloud Platform Console, click Navigation menu > Cloud Storage > Browser.
-
Click Create Bucket. Set the following values, leave all other values at their defaults:
- Name: id-cards-photo
- Location type and Location: Region, asia-southeast2 (Jakarta)
- Default storage class: Standard
- Access control: Fine-grained
-
Click Create, then click Browser from the left hand menu. Check the bucket that was created earlier, then click three dots to the right of the bucket, then select Edit access.
-
Click Add Principal. Set the following values, leave all other values at their defaults:
- New principals: allUsers
- Role: Storage Object Viewer
-
Click Save, then click Allow Public Access when the popup appears.
-
Click Navigation menu > Firestore. Then click Select Native Mode button.
-
In the Select a location dropdown, choose asia-southeast2 (Jakarta), then click Create Database.
-
In the top right toolbar, click the Activate Cloud Shell button.
-
From Cloud Shell, enable the Container Registry, Cloud Build, and Cloud Run APIs:
gcloud services enable \ containerregistry.googleapis.com \ cloudbuild.googleapis.com \ run.googleapis.com
-
Run the following command to clone this repository:
git clone https://github.com/C22-KY04/cc-c22-ky04.git
-
Click Open Editor button on the Cloud Shell Terminal toolbar. Then upload the
serviceAccountKey.json
obtained from step 5 of Firebase setup to the root directory: -
If you create a bucket with a different name from step 2 of the Google Cloud Platform setup, then replace the bucket name in the cc-c22-ky04/optical-character-recognition-api/app.py on line 44:
# Replace with the name of the bucket you created bucket_name = "id-cards-photo"
-
Don't forget to change your Google Cloud Platform Project ID in the
deploy.sh
located at: -
Run the following command to deploy Optical Character Recognition API to Cloud Run:
cd ~/cc-c22-ky04/optical-character-recognition-api chmod +x deploy.sh ./deploy.sh
Wait a few moments until the deployment is complete. Open the service URL in any browser window and you will get the result:
"Hello from Optical Character Recognition API, C22-KY04."
-
Click Open Terminal button on the Cloud Shell Editor toolbar. Run the following command to deploy ID Cards API to Cloud Run:
cd ~/cc-c22-ky04/id-cards-api chmod +x deploy.sh ./deploy.sh
Wait a few moments until the deployment is complete. Open the service URL in any browser window and you will get the result:
"Hello from ID Cards API, C22-KY04."
Description:
- Firebase Authentication will send JWT token to Android Application.
- Android Application will send the JWT token to the Cloud Run Service. Then Cloud Run Service will validate the token, so only authenticated users can make requests.
Create REST API using Python, Flask, TensorFlow, PyTesseract, Cloud Run, and Cloud Storage
Description:
- Upload to Google Cloud Storage Bucket using HTTP Request Method
POST
. - Download images from Google Cloud Storage Bucket.
- Classify images using TensorFlow, whether the image is ID card or not.
- If the image is not an ID card (KTP), then immediately return the results to the Android Application.
- If the image is an ID card (KTP), then proceed to collect the details.
- Collect ID Card (KTP) details using PyTesseract (Python Tesseract).
- Then send the results to the Android Application for re-validation.
https://ocr-api-s77adt3hmq-et.a.run.app
Response string
"Hello from Optical Character Recognition API, C22-KY04."
POST /ocr
This method allows you to classify an image as ID card or not and extract data on ID card.
Authentication
- ID Tokens
Headers
Authorization | string | Bearer <ID Tokens> | required |
Request Body multipart/form-data
file | File | png / jpg / jpeg | required |
Response application/json
HTTP Response Status Codes 201
{
"status": "OK",
"message": "Successfully extract data with OCR.",
"data": {
"province": "JAWA TIMUR",
"district": "KABUPATEN SIDOARJO",
"id_number": "351XXXXXXXXXXXXX",
"name": "MOCHAMMAD ARYA SALSABILA",
"place_date_of_birth": "SIDOARJO, 24-06-2001",
"gender": "LAKI-LAKI",
"blood_type": "-",
"address": "NGABAN",
"neighborhood": "005/002",
"village": "NGABAN",
"subdistrict": "TANGGULANGIN",
"religion": "ISLAM",
"marital_status": "BELUM KAWIN",
"occupation": "PELAJAR/MAHASISWA",
"nationality": "WNI",
"expiry_date": "SEUMUR HIDUP",
"attachment": "https://storage.googleapis.com/id-cards-photo/04062022-090807.png"
}
}
HTTP Response Status Codes 400
{
"status": "Bad Request",
"message": "No token provided."
}
{
"status": "Bad Request",
"message": "No file part."
}
{
"status": "Bad Request",
"message": "No selected file."
}
HTTP Response Status Codes 406
{
"status": "Not Acceptable",
"message": "Only files with extension png, jpg, jpeg are allowed."
}
{
"status": "Not Acceptable",
"message": "That's not an Indonesian ID Card (KTP). Please try again."
}
HTTP Response Status Codes 500
{
"status": "Internal Server Error",
"message": "Error message..."
}
Create a REST API using Node.js, Express, Firebase Auth, Cloud Run, and Cloud Firestore.
Description:
- Android Application performs the HTTP Request Method to the HTTP REST API. Some of the methods that can be used are:
POST
to save ID Card (KTP) details.GET
to retrieve entire ID Cards, or retrieve some ID Cards by name.
- If the HTTP Request Method sent is
POST
, the ID Card (KTP) details will be saved to Cloud Firestore.
https://id-cards-api-s77adt3hmq-et.a.run.app
Response string
"Hello from ID Cards API, C22-KY04."
POST /id_cards
This method allows you to save ID Card details.
Authentication
- ID Tokens
Headers
Authorization | string | Bearer <ID Tokens> | required |
Request Body application/json
{
"province": "JAWA TIMUR",
"district": "KABUPATEN SIDOARJO",
"id_number": "351XXXXXXXXXXXXX",
"name": "MOCHAMMAD ARYA SALSABILA",
"place_date_of_birth": "SIDOARJO, 24-06-2001",
"gender": "LAKI-LAKI",
"blood_type": "-",
"address": "NGABAN",
"neighborhood": "005/002",
"village": "NGABAN",
"subdistrict": "TANGGULANGIN",
"religion": "ISLAM",
"marital_status": "BELUM KAWIN",
"occupation": "PELAJAR/MAHASISWA",
"nationality": "WNI",
"expiry_date": "SEUMUR HIDUP",
"attachment": "https://storage.googleapis.com/id-cards-photo/u10rFTlsFwSaeAJ3d6DhcaCZqWX2.png"
}
Response application/json
HTTP Response Status Codes 201
{
"status": "Created",
"message": "The item/record was created successfully."
}
HTTP Response Status Codes 400
{
"status": "Bad Request",
"message": "No token provided."
}
{
"status": "Bad Request",
"message": "Error message..."
}
HTTP Response Status Codes 401
{
"status": "Unauthorized",
"message": "You do not have permissions to access the service."
}
GET /id_cards
This method allows you to retrieve the entire ID Cards / retrieve some ID Cards by name.
Authentication
- ID Tokens
Headers
Authorization | string | Bearer <ID Tokens> | required |
Query String
name | string | Pass a text query to search | optional |
Response application/json
HTTP Response Status Codes 200
{
"status": "OK",
"message": "The items/records was retrieved successfully.",
"data": [
{
"province": "JAWA TIMUR",
"district": "KABUPATEN SIDOARJO",
"id_number": "351XXXXXXXXXXXXX",
"name": "MOCHAMMAD ARYA SALSABILA",
"place_date_of_birth": "SIDOARJO, 24-06-2001",
"gender": "LAKI-LAKI",
"blood_type": "-",
"address": "NGABAN",
"neighborhood": "005/002",
"village": "NGABAN",
"subdistrict": "TANGGULANGIN",
"religion": "ISLAM",
"marital_status": "BELUM KAWIN",
"occupation": "PELAJAR/MAHASISWA",
"nationality": "WNI",
"expiry_date": "SEUMUR HIDUP",
"attachment": "https://storage.googleapis.com/id-cards-photo/u10rFTlsFwSaeAJ3d6DhcaCZqWX2.png"
},
{
"province": "JAWA TIMUR",
"district": "KABUPATEN SIDOARJO",
"id_number": "351XXXXXXXXXXXXX",
"name": "MOCHAMMAD ARYA SALSABILA",
"place_date_of_birth": "SIDOARJO, 24-06-2001",
"gender": "LAKI-LAKI",
"blood_type": "-",
"address": "NGABAN",
"neighborhood": "005/002",
"village": "NGABAN",
"subdistrict": "TANGGULANGIN",
"religion": "ISLAM",
"marital_status": "BELUM KAWIN",
"occupation": "PELAJAR/MAHASISWA",
"nationality": "WNI",
"expiry_date": "SEUMUR HIDUP",
"attachment": "https://storage.googleapis.com/id-cards-photo/u10rFTlsFwSaeAJ3d6DhcaCZqWX2.png"
}
]
}
HTTP Response Status Codes 400
{
"status": "Bad Request",
"message": "No token provided."
}
{
"status": "Bad Request",
"message": "Error message..."
}
HTTP Response Status Codes 401
{
"status": "Unauthorized",
"message": "You do not have permissions to access the service."
}
HTTP Response Status Codes 404
{
"status": "Not Found",
"message": "The item/record not found."
}
Distributed under the MIT License. See LICENSE
for more information.