upload method

Future<Attachment> upload(
  1. CreateAttachmentRequest request,
  2. String parent, {
  3. String? $fields,
  4. Media? uploadMedia,
})

Create a file attachment on a case or Cloud resource.

The attachment must have the following fields set: filename. EXAMPLES: cURL: ```shell 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:python import googleapiclient.discovery api_version = "v2" supportApiService = googleapiclient.discovery.build( serviceName="cloudsupport", version=api_version, discoveryServiceUrl=f"https://cloudsupport.googleapis.com/$discovery/rest?version={api_version}", ) 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())


[request] - The metadata request object.

Request parameters:

[parent] - Required. The name of the case or Cloud resource to which the
attachment should be attached.
Value must have pattern `^\[^/\]+/\[^/\]+/cases/\[^/\]+$`.

[$fields] - Selector specifying which fields to include in a partial
response.

[uploadMedia] - The media to upload.

Completes with a [Attachment].

Completes with a [commons.ApiRequestError] if the API endpoint returned an
error.

If the used [http.Client] completes with an error when making a REST call,
this method will complete with the same error.

Implementation

async.Future<Attachment> upload(
  CreateAttachmentRequest request,
  core.String parent, {
  core.String? $fields,
  commons.Media? uploadMedia,
}) async {
  final body_ = convert.json.encode(request);
  final queryParams_ = <core.String, core.List<core.String>>{
    if ($fields != null) 'fields': [$fields],
  };

  core.String url_;
  if (uploadMedia == null) {
    url_ = 'v2beta/' + core.Uri.encodeFull('$parent') + '/attachments';
  } else {
    url_ =
        '/upload/v2beta/' + core.Uri.encodeFull('$parent') + '/attachments';
  }

  final response_ = await _requester.request(
    url_,
    'POST',
    body: body_,
    queryParams: queryParams_,
    uploadMedia: uploadMedia,
    uploadOptions: commons.UploadOptions.defaultOptions,
  );
  return Attachment.fromJson(
      response_ as core.Map<core.String, core.dynamic>);
}