GCP Engineer: Memigrasikan Alur Kerja App Engine Blobstore Lawas ke V4 Signed URL Google Cloud Storage
Aplikasi Google App Engine (GAE) lawas sering kali masih mengandalkan API khusus google.appengine.ext.blobstore (create_upload_url dan BlobKey) untuk menangani unggahan dan unduhan file pengguna. Namun, referensi BlobKey mengunci aplikasi Anda pada runtime App Engine, menghambat interoperabilitas langsung dengan Cloud Run, BigQuery, atau Vertex AI. Sebagai Google Cloud Platform (GCP) Engineer bersertifikat, saya memigrasikan sistem Blobstore lawas ke V4 Signed URL Google Cloud Storage (GCS) asli tanpa memutus tautan unduhan historis.
1. Menghasilkan V4 Signed URL Langsung ke GCS dengan Batas Ukuran Ketat
Backend kami menghasilkan V4 Signed URL yang menegakkan tipe konten HTTP PUT dan batas ukuran byte secara langsung di tepi jaringan Google Cloud Storage:
from datetime import timedelta
from google.cloud import storage
def generate_gcs_v4_signed_upload_url(
bucket_name: str,
object_name: str,
content_type: str,
max_expiration_minutes: int = 15,
) -> str:
client = storage.Client()
bucket = client.bucket(bucket_name)
blob = bucket.blob(object_name)
return blob.generate_signed_url(
version="v4",
expiration=timedelta(minutes=max_expiration_minutes),
method="PUT",
content_type=content_type,
headers={"x-goog-content-length-range": "1,26214400"}, # Batas 1 byte hingga 25 MB
)
2. Resolusi Dual-Read BlobKey Lawas & Siklus Hidup Penyimpanan Objek
Selama masa transisi, entitas database lama masih menyimpan string blob_key berdampingan dengan atribut gcs_uri baru. Adapter penyimpanan kami melayani kedua format tersebut secara transparan sementara pekerjaan latar belakang Cloud Run menyalin blob historis ke bucket GCS dengan kebijakan siklus hidup otomatis—terintegrasi dengan arsitektur microservice App Engine & Cloud Run serta cetak biru produksi GCP Engineer. Kunjungi Layanan Sprint Teknik 1 Hari untuk modernisasi penyimpanan GCP Anda.