Method: media.upload

在支持请求或 Cloud 资源上创建文件附件。

必须为附件设置以下字段:filename

示例:

c网址:

echo "This text is in a file I'm uploading using CSAPI." \
  > "./example_file.txt"
case="projects/some-project/cases/43594844"
curl \
  --header "Authorization: Bearer $(gcloud auth print-access-token)" \
  --data-binary @"./example_file.txt" \
  "https://cloudsupport.googleapis.com/upload/v2beta/$case/attachments?attachment.filename=uploaded_via_curl.txt"

Python:

import googleapiclient.discovery


apiVersion = "v2"
supportApiService = googleapiclient.discovery.build(
    serviceName="cloudsupport",
    version=apiVersion,
    discoveryServiceUrl=f"https://cloudsupport.googleapis.com/$discovery/rest?version={apiVersion}",
)

file_path = "./example_file.txt"
with open(file_path, "w") as file:
    file.write(
        "This text is inside a file I'm going to upload using the Cloud
        Support API.",
    )

request = supportApiService.media().upload(
    parent="projects/some-project/cases/43595344",
    media_body=file_path
)
request.uri = request.uri.split("?")[0] +
"?attachment.filename=uploaded_via_python.txt" print(request.execute())

HTTP 请求

  • 上传 URI,用于媒体上传请求:
    POST https://cloudsupport.googleapis.com/upload/v2beta/{parent=*/*/cases/*}/attachments
  • 元数据 URI,用于仅包含元数据的请求:
    POST https://cloudsupport.googleapis.com/v2beta/{parent=*/*/cases/*}/attachments

网址采用 gRPC 转码语法。

路径参数

参数
parent

string

必需。应附加连接的案例或 Cloud 资源的名称。

请求正文

请求正文中包含结构如下的数据:

JSON 表示法
{
  "attachment": {
    object (Attachment)
  }
}
字段
attachment

object (Attachment)

必需。要创建的连接。

响应正文

如果成功,则响应正文包含一个 Attachment 实例。

授权范围

需要以下 OAuth 范围之一:

  • https://www.googleapis.com/auth/cloudsupport
  • https://www.googleapis.com/auth/cloud-platform

如需了解详情,请参阅身份验证概览