您可以提供可公開存取的網址,也可以提供 base64 編碼圖片字串。如要取得後者,您可以使用下列程式碼,從 Google 雲端硬碟中的圖片建立經過編碼的圖片字串,然後儲存該字串,以便日後搭配 setImageUrl(imageUrl) 使用。這個方法可避免外掛程式需要存取公開圖片網址:
// The following assumes you have the image to use in Google Drive and have its// ID.constimageBytes=DriveApp.getFileById('123abc').getBlob().getBytes();constencodedImageURL=`data:image/jpeg;base64,${Utilities.base64Encode(imageBytes)}`;// You can store encodeImageURL and use it as a parameter to// CardHeader.setImageUrl(imageUrl).
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-01-30 (世界標準時間)。"],[[["`CardHeader` objects allow you to customize the header of a card, including title, subtitle, and image, within Google Workspace Add-ons and Google Chat apps."],["You can set an image for the header using `setImageUrl()` by providing a public URL or a base64 encoded image string."],["`setTitle()` and `setSubtitle()` allow you to define the main text and supporting text for the header, respectively."],["Customize the image display with `setImageStyle()` to control cropping and use `setImageAltText()` to provide alternative text for accessibility."]]],["The `CardHeader` object allows customization of a card's header in Google Workspace add-ons and Google Chat apps. Key actions include setting the header's title using `setTitle()`, a subtitle with `setSubtitle()`, and an image via `setImageUrl()`. The image's appearance can be modified with `setImageStyle()` for cropping and `setImageAltText()` for alternative text. Image URLs can be direct links or base64 encoded strings. Each method returns the `CardHeader` object, enabling method chaining.\n"]]