upload method

Future<UploadAttachmentResponse> upload(
  1. UploadAttachmentRequest request,
  2. String parent, {
  3. String? $fields,
  4. UploadOptions uploadOptions = commons.UploadOptions.defaultOptions,
  5. Media? uploadMedia,
})

Uploads an attachment.

For an example, see Upload media as a file attachment. Requires user authentication. You can upload attachments up to 200 MB. Certain file types aren't supported. For details, see File types blocked by Google Chat.

request - The metadata request object.

Request parameters:

parent - Required. Resource name of the Chat space in which the attachment is uploaded. Format "spaces/{space}". Value must have pattern ^spaces/\[^/\]+$.

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

uploadMedia - The media to upload.

uploadOptions - Options for the media upload. Streaming Media without the length being known ahead of time is only supported via resumable uploads.

Completes with a UploadAttachmentResponse.

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<UploadAttachmentResponse> upload(
  UploadAttachmentRequest request,
  core.String parent, {
  core.String? $fields,
  commons.UploadOptions uploadOptions = commons.UploadOptions.defaultOptions,
  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_ = 'v1/' + core.Uri.encodeFull('$parent') + '/attachments:upload';
  } else if (uploadOptions is commons.ResumableUploadOptions) {
    url_ = '/resumable/upload/v1/' +
        core.Uri.encodeFull('$parent') +
        '/attachments:upload';
  } else {
    url_ = '/upload/v1/' +
        core.Uri.encodeFull('$parent') +
        '/attachments:upload';
  }

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