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.

request - The metadata request object.

Request parameters:

parent - Required. The resource name of the case to which 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>);
}