發表文章

目前顯示的是 4月, 2017的文章

How to upload file to Storage without login

圖片
In order to upload file to Storage without login google account, we have to implement policy document. After that, user can upload file to Storage from web page via Form directly. There are 4 rough steps: Service Account p12 file, it can be created at  GCP Console   Uploading object metadata, including Bucket Key ACL Expiration, for more information:  Policy Document encryption fill above info to Form, upload file Step One:p12 file After login GCP Console , you can generate p12 file via API Manager -> Credentials -> Create credentials Only Storage Admin assigned because we utilize Storage service only. If you need more permissions for other services, please refer available roles. Please save your p12 file properly because there is only one chance to download the file. Step Two:uploading object metadata According to  Policy Document , JSON format is required for uploading object metadata. There are two major parts:  expiration:policy

如何在不登入的情況下開放使用者上傳檔案到 Storage

圖片
找了好久終於找到  Policy Document  能夠在不登入 Google Account 的情況下,讓使用者能夠直接在網頁中透過 Form 上傳檔案到 Storage。 以下將分成四個部分來說明,先大致敘述一下流程 準備 Service Account p12 檔,可在 GCP Console  建立 準備要上傳物件的描述內容,包括 Bucket Key ACL Expiration 等等,其他內容可以參考  Policy Document 加密 將資訊填入 Form 後,上傳檔案 第一步:準備p12檔 登入  GCP Console  後可在 API 管理員 -> 憑證 -> 建立憑證 連結裡建立需要的憑證檔案 由於我們只需要用到 Storage 的功能,所以再分配角色權限上只需要分配對應的權限即可,如果需要用到其他服務則可參考能分配的權限進行分配。 建立好建立好服務帳戶後,p12檔會自動下載 到本機端。這個檔案只有一次下載機會,請務必保管好。 第二步:準備上傳物件的描述內容 根據  Policy Document  的說明,我們必須使用 JSON 格式來描述要上傳檔案的內容。其中必填的兩大項為  expiration:過期時間 ( ISO8601 格式),當每次簽署  Policy Document  時,需要指定一個有效期限,當超過有效期限,則簽署會失效 conditions:描述上傳檔案內容 範例: {"expiration":"2017-04-24T11:11:51+02:00",   "conditions":[{"bucket":"upload"}, {"key":"myimg.png"}]} PHP Sample Code 第三步:加密 這個步驟要小心注意加密的順序,以及確認 p12 所在位置無誤 policy 必須是 utf-8 編碼 => policy_utf Base64 encode (policy_utf) => policy_