[[["容易理解","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-08-29 (世界標準時間)。"],[],[],null,["# Upgrade Link attachments to Classroom add-on attachments\n\nOne way that teachers add third-party content to Classroom is by\npasting a link as a [Link attachment](/workspace/classroom/reference/rest/v1/Link) in the assignment creation page. To build\non what teachers are already familiar with, you can now configure your add-on to\nlet teachers upgrade a Link attachment to an [add-on attachment](/workspace/classroom/reference/rest/v1/courses.courseWork.addOnAttachments#AddOnAttachment).\n\nOverview\n--------\n\nIf you configure your add-on with this capability, teachers are prompted to\nupgrade a link to an add-on attachment when they paste a Link attachment in the\nassignment creation page. Teachers are only prompted to do so if they already\nhave the add-on installed.\n\nOnce the teacher agrees to upgrade the link to an add-on attachment, the Link\nUpgrade iframe is launched with the following query parameters:\n\n- `courseId`\n- `itemId`\n- `itemType`\n- `addOnToken`\n- `urlToUpgrade`\n- `login_hint` (only if the user has already authorized your app)\n\nThe first four query parameters mirror the query parameters launched on the\n[Attachment Discovery iframe](/workspace/classroom/add-ons/technical-details/iframes#attachment_discovery_iframe). The `urlToUpgrade` query parameter is new and can\nhelp you evaluate how the add-on attachment should be created. Then, you can use\nthe other query parameters to check if the user is signed-in and call the\n`CreateAddOnAttachment` method of `courseWork`, `courseWorkMaterials` or\n`announcements` based on the `itemType` value. Within the iframe, you can\ndisplay a loading screen to indicate to the teacher that the add-on attachment\nis being created.\n\nOnce the add-on attachment has been created, the iframe is closed and the\nteacher can view the attachment in the assignment as they normally would.\n\nTechnical implementation details\n--------------------------------\n\nThis section highlights some important technical details for the feature.\n\n### Read the `urlToUpgrade` query parameter\n\nThe `urlToUpgrade` query parameter is URI encoded when it's passed on the Link\nUpgrade iframe. You must decode the URL to obtain it in its original form. If\nyou're using JavaScript, for example, you can use the `decodeURIComponent()`\nfunction to do so.\n\n### Close the Link Upgrade iframe\n\nTo ensure an optimal user experience for this feature, send a `postMessage` once\nthe add-on attachment has been successfully created. This closes the iframe. See\nthe [iframe implementation details page](/workspace/classroom/add-ons/developer-guides/iframes#closing_the_iframe) for more details.\n\n### Configuration details\n\nThe following configurations are required to integrate this feature into your\nadd-on:\n\n- **URL for the Link Upgrade iframe**: This is the URL that opens in the\n iframe when a teacher agrees to upgrade.\n\n- **URL patterns that Classroom should detect and attempt to\n upgrade**: The URL patterns can consist of a host and multiple path\n prefixes.\n\n - You can provide multiple URL patterns.\n - If you don't provide any path prefixes, any URL that matches the host can be upgraded.\n - Only URLs with an `https` scheme can be upgraded.\n - URL patterns must not contain `localhost`.\n - Path prefixes must not contain query parameters or URL fragments.\n - Path prefixes can support wildcards at this time, but hosts can't:\n - `example.com` is a valid host, and `/foo` and `/bar/*/baz` are valid path prefixes.\n - `example.*.host.com` is not a valid host.\n - A wildcard between path prefix components only matches a single component, and doesn't match multiple components separated by slashes. Consider a URL pattern with the host `example.com` and path prefix `/bar/*/baz`:\n - `https://example.com/bar/123/baz` is a valid match for the URL pattern.\n - `https://example.com/bar/123/baz/456/789` is a valid match for the URL pattern.\n - `https://example.com/bar/123/456/baz` is not a valid match for the URL pattern because the wildcard in the path prefix doesn't match `/123/456/`.\n\n| **Note:** Wildcards between path prefix components only match a single component.\n\n### Development process\n\nSend the Link Upgrade iframe URL and URL patterns for your test or production\nadd-on by emailing [classroom-link-upgrade-external@google.com](mailto:classroom-link-upgrade-external@google.com).\n\nYou can provide configurations for any Google Cloud project that represents a\nClassroom add-on. We recommend that you first provide\nconfigurations for an add-on with private visibility so that you can develop\nand test in a demo domain without affecting live users.\n\nYou will receive a response to your email when the configurations have been\nenabled. Note that URL patterns that use `localhost` are not supported for this\nfeature.\n| **Important:** Users that can install and use your add-on can upgrade links to add-on attachments as soon as the configurations are enabled by the Classroom team. This is why it is important to first provide configurations for your test add-on within a test or dev environment before providing any production configurations.\n\nFormat the email to include the following: \n\n Google Cloud Project number: \u003cvar label=\"bucket name\" translate=\"no\"\u003eGCP_PROJECT_NUMBER\u003c/var\u003e\n\n Link Upgrade iframe URL: \u003cvar label=\"bucket name\" translate=\"no\"\u003eLINK_UPGRADE_IFRAME_URL\u003c/var\u003e\n\n URL Patterns:\n - Host:\u003cvar label=\"bucket name\" translate=\"no\"\u003eHOST_1\u003c/var\u003e\n - Path prefixes:\n - \u003cvar label=\"bucket name\" translate=\"no\"\u003ePATH_PREFIX_1\u003c/var\u003e\n - \u003cvar label=\"bucket name\" translate=\"no\"\u003ePATH_PREFIX_2\u003c/var\u003e\n\n - Host:\u003cvar label=\"bucket name\" translate=\"no\"\u003eHOST_2\u003c/var\u003e\n - Path prefixes:\n - \u003cvar label=\"bucket name\" translate=\"no\"\u003ePATH_PREFIX_3\u003c/var\u003e\n - \u003cvar label=\"bucket name\" translate=\"no\"\u003ePATH_PREFIX_4\u003c/var\u003e\n\n // add more hosts and path prefixes as needed\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eGCP_PROJECT_NUMBER\u003c/var\u003e: The number of the Google Cloud project that the add-on is associated with.\n- \u003cvar translate=\"no\"\u003eLINK_UPGRADE_IFRAME_URL\u003c/var\u003e: The URL that should open in the Link Upgrade iframe.\n- \u003cvar translate=\"no\"\u003eHOST_1\u003c/var\u003e: A host that Classroom should detect. Only the `https` scheme is supported.\n- \u003cvar translate=\"no\"\u003ePATH_PREFIX_1\u003c/var\u003e and \u003cvar translate=\"no\"\u003ePATH_PREFIX_2\u003c/var\u003e: Path prefixes associated with `HOST_1` that Classroom should detect and attempt to upgrade.\n- \u003cvar translate=\"no\"\u003eHOST_2\u003c/var\u003e: A host that Classroom should detect. Only the `https` scheme is supported.\n- \u003cvar translate=\"no\"\u003ePATH_PREFIX_3\u003c/var\u003e and \u003cvar translate=\"no\"\u003ePATH_PREFIX_4\u003c/var\u003e: Path prefixes associated with `HOST_2` that Classroom should detect and attempt to upgrade.\n\nRecommended user experience\n---------------------------\n\nThe following are suggestions to consider when implementing this feature.\n\n### Avoid extra work for teachers\n\nWe strongly recommend that you use the iframe to facilitate sign-in, if\nrequired, or display a loading indicator. For the best user experience, the\nteacher shouldn't be prompted for any additional information after they have\nagreed to upgrade the pasted link to an add-on attachment. However, if this is\nnot possible for your add-on, you can use the Link Upgrade iframe to collect\nadditional information that you need. The iframe can also be used to inform the\nteacher if upgrading the link is not possible or if an error occurred.\n\n### Include user-friendly access error messages\n\nIf teachers paste and upgrade a link that they don't have access to, display a\nuser-friendly error message in the iframe so teachers are aware of the issue.\nThe iframe can also be used to provide the teacher with the appropriate\npermissions to access the content."]]