new_releases 更新:查看
版本資訊瞭解新功能和產品更新。
Method: files.create
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
上傳檔案,用於媒體或互動式資訊卡訊息。
代理程式會提供檔案的網址或二進位檔,以及對應縮圖檔案的網址 (選用)。
重要事項:為保障使用者的隱私權和安全,RBM 平台會先從提供的網址下載及處理媒體和 PDF 檔案,再交付給使用者。這會導致代理程式無法追蹤專屬網址。因此,請勿提交大量專屬網址。無論網址指向相同或不同檔案,RBM 平台都不支援這項操作。針對相同的檔案使用相同的網址。
RBM 平台會將檔案快取 60 天,並傳回專屬名稱,方便您在傳送服務機器人訊息時識別檔案。
如要上傳檔案二進位檔,請對上傳 URI 發出 HTTP POST 要求,從 JSON 要求主體中省略 fileUrl
欄位,並將二進位檔指定為 POST 要求主體。例如,請使用 --upload-file
cURL 旗標搭配二進位檔案的完整檔案路徑。
HTTP 要求
- 上傳 URI,適用於媒體上傳要求:
POST https://rcsbusinessmessaging.googleapis.com/upload/v1/files
- 中繼資料 URI (僅限中繼資料要求):
POST https://rcsbusinessmessaging.googleapis.com/v1/files
這個網址使用 gRPC 轉碼語法。
要求主體
要求主體的資料會採用以下結構:
JSON 表示法 |
{
"fileUrl": string,
"thumbnailUrl": string,
"agentId": string
} |
欄位 |
fileUrl |
string
(選用步驟) 檔案的公開網址。擷取檔案時,RBM 平台會根據 HTTP 標頭中的 content-type 欄位,判斷檔案的 MIME 類型。RBM 支援圖片、音訊、影片和 PDF。 支援的圖片內容類型:image/jpeg、image/jpg、image/gif、image/png。 支援的音訊內容類型:audio/aac、audio/mp3、audio/mpeg、audio/mpg、audio/mp4、audio/mp4-latm、audio/3gpp、application/ogg、audio/ogg。 支援的影片內容類型:video/h263、video/m4v、video/mp4、video/mpeg、video/mpeg4、video/webm。 支援的 PDF 內容類型:application/pdf。 注意:檔案網址可有 1 個重新導向。重新導向的檔案網址必須可供所有人存取。CreateAgentMessageRequest 中的檔案網址不支援重新導向。
|
thumbnailUrl |
string
(選用步驟) 與檔案相對應的縮圖公開網址。如果未設定這個欄位,RBM 平台會自動從檔案產生縮圖。擷取檔案時,RBM 平台會根據 HTTP 標頭中的 content-type 欄位,判斷檔案的 MIME 類型。 支援的圖片內容類型:image/jpeg、image/jpg、image/gif、image/png。
|
agentId |
string
必要欄位。代理程式的專屬 ID。
|
回應主體
檔案資源,具有不重複的名稱,可讓服務專員在傳送訊息時識別檔案。
如果成功,回應主體會含有以下結構的資料:
JSON 表示法 |
{
"name": string
} |
欄位 |
name |
string
伺服器指派的檔案資源專屬名稱,可供服務專員在傳送訊息時用於識別檔案。格式為「files/{uid}」,其中 {uid} 是專屬 ID。
|
授權範圍
需要下列 OAuth 範圍:
https://www.googleapis.com/auth/rcsbusinessmessaging
詳情請參閱 OAuth 2.0 Overview。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\u003cp\u003eThis process allows agents to upload files, including images, audio, video, and PDFs, for use in media or rich card messages, either by providing a public URL or the file's binary data.\u003c/p\u003e\n"],["\u003cp\u003eThe RBM platform handles file privacy and security by downloading and processing media files from provided URLs, preventing agent tracking via unique URLs, and caches the file for 60 days.\u003c/p\u003e\n"],["\u003cp\u003eThe file upload requires an HTTP POST request to either the upload URI \u003ccode\u003ehttps://rcsbusinessmessaging.googleapis.com/upload/v1/files\u003c/code\u003e or the metadata-only URI \u003ccode\u003ehttps://rcsbusinessmessaging.googleapis.com/v1/files\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe agent can provide a public \u003ccode\u003efileUrl\u003c/code\u003e, \u003ccode\u003ethumbnailUrl\u003c/code\u003e, and must include the \u003ccode\u003eagentId\u003c/code\u003e within the request body to upload files.\u003c/p\u003e\n"],["\u003cp\u003eUpon successful upload, the RBM platform returns a unique file name (\u003ccode\u003ename\u003c/code\u003e) that agents can use to reference the file in subsequent messages.\u003c/p\u003e\n"]]],[],null,["# Method: files.create\n\nUploads a file for use in media or rich card messages.\n\nThe agent provides the URL or binary of the file and (optionally) the URL of the corresponding thumbnail file.\n\nImportant: For user privacy and security, the RBM platform downloads and processes media and PDF files from the provided URLs before delivering them to the user. This prevents agent tracking by unique URLs. Therefore, do not submit a high volume of unique URLs. The RBM platform does not support this, whether the URLs point to the same or different files. Use the same URL for identical files.\n\nThe RBM platform caches the file for 60 days and returns a unique name that you can use to identify the file when sending agent messages.\n\nTo upload a file binary, make an HTTP POST request to the Upload URI, omit the `fileUrl` field from the JSON request body, and specify the binary as the POST request body. For example, use the `--upload-file` cURL flag with the fully qualified file path of the binary file.\n\n### HTTP request\n\n- Upload URI, for media upload requests: \n `POST https://rcsbusinessmessaging.googleapis.com/upload/v1/files`\n- Metadata URI, for metadata-only requests: \n `POST https://rcsbusinessmessaging.googleapis.com/v1/files`\n\nThe URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.\n\n### Request body\n\nThe request body contains data with the following structure:\n\n| JSON representation |\n|--------------------------------------------------------------------------|\n| ``` { \"fileUrl\": string, \"thumbnailUrl\": string, \"agentId\": string } ``` |\n\n| Fields ||\n|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `fileUrl` | `string` Optional. Publicly available URL of the file. The RBM platform determines the MIME type of the file from the content-type field in the HTTP headers when fetching the file. RBM supports image, audio, video, and pdf. Supported image content types: image/jpeg, image/jpg, image/gif, image/png. Supported audio content types: audio/aac, audio/mp3, audio/mpeg, audio/mpg, audio/mp4, audio/mp4-latm, audio/3gpp, application/ogg, audio/ogg. Supported video content types: video/h263, video/m4v, video/mp4, video/mpeg, video/mpeg4, video/webm. Supported pdf content types: application/pdf. Note: file URL can have 1 redirect. Redirected file URLs must be publicly accessible. Redirects are not supported for file URLs in CreateAgentMessageRequest. |\n| `thumbnailUrl` | `string` Optional. Publicly available URL of the thumbnail corresponding to the file. If this field is not set, then the RBM platform automatically generates a thumbnail from the file. The RBM platform determines the MIME type of the file from the content-type field in the HTTP headers when fetching the file. Supported image content types: image/jpeg, image/jpg, image/gif, image/png. |\n| `agentId` | `string` Required. The agent's unique identifier. |\n\n### Response body\n\nA file resource with a unique name that an agent can use to identify the file when sending messages.\n\nIf successful, the response body contains data with the following structure:\n\n| JSON representation |\n|----------------------------|\n| ``` { \"name\": string } ``` |\n\n| Fields ||\n|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `name` | `string` Server-assigned unique name of the file resource, which an agent can use to identify the file when sending messages. The format is \"files/{uid}\", where {uid} is a unique ID. |\n\n### Authorization scopes\n\nRequires the following OAuth scope:\n\n- `https://www.googleapis.com/auth/rcsbusinessmessaging`\n\nFor more information, see the [OAuth 2.0 Overview](/identity/protocols/OAuth2)."]]