發表文章

目前顯示的是有「gcp」標籤的文章

[Node.js]計算檔案雜湊用來比對Cloud Storage的md5Hash

圖片
由於Cloud Storage返回的Metadata的md5Hash值是BASE64編碼過得資料,如下附圖,要比對是否相同需要生成相同的值。 這篇裡面會分別給予BASH指令和Node.js程式如何作用來比對GCS檔案的md5雜湊值

[Next.js][App router]使用Route Handler處理檔案上傳(Firebase hosting/Cloud functions)

一個會員網站提供上傳個人圖檔是一個很基本的應用。現在如AI解析及互動上也會需要用到圖檔、聲音,甚至是影片來提供服務,所以上傳檔案是一件稀鬆平常的事情。 當然,firebase中,可以透過使用Firebase storage的前端套件來快速的完成這件事情,不需要額外思考檔案上傳背後的問題。然而,當你沒有使用Firebase Auth來作會員登入系統,你馬上就面臨資料隱私的兩難問題。 你的Firebase storage存取規則無法檢驗存取的是否為用戶,且無法依照會員角色來區分存取權限。直到最後你只能妥協,將storage存取權限完全開放,使得上傳功能與用戶資料完全裸奔在網際網路上。在App router中透過Route Handler,我們可以管控會員是否有上傳與存取的權利。

Google官方針對Next.js整合到firebase推出的codelabs教學

圖片
這幾天照著 這個codelabs教學 跑了一下,遭遇滿多小問題的,不過拿來當實作得參考程式碼是不錯的。 上圖使用 Coplit設計工具 生成 https://firebase.google.com/codelabs/firebase-nextjs 上面這篇教學是使用Next.js並推廣firebase app hosting和github整合,當然也沒有缺少AI的部份(Gemini API),不過所佔篇幅只有一個小節。使用到得服務有: Firebase authentication 使用者的Google整合登入 Firebase storage 儲存上傳圖片 Firestore 儲存/存取使用者評論與評分等 Gemini API  Cloud Secret Manager 儲存密鑰

解決Firebase整合Next.js部屬(deploy)的permission問題

圖片
  這是在轉移之前寫的next.js功能到其他firebase專案時發生的權限問題 摘要錯誤訊息如下: i  functions: creating Node.js 18 (2nd Gen) function firebase-frameworks-***:ssr***(asia-east1)...     Unable to retrieve the repository metadata for projects/ *** /locations/asia-east1/repositories/gcf-artifacts. Ensure that the Cloud Functions service account has 'artifactregistry.repositories.list' and 'artifactregistry.repositories.get' permissions. You can add the permissions by granting the role 'roles/artifactregistry.reader'.     Functions deploy had errors with the following functions:             firebase-frameworks- *** :ssr***(asia-east1)