upload method

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

Uploads media for indexing.

The upload endpoint supports direct and resumable upload protocols and is intended for large items that can not be inlined during index requests. To index large content: 1. Call indexing.datasources.items.upload with the item name to begin an upload session and retrieve the UploadItemRef. 1. Call media.upload to upload the content, as a streaming request, using the same resource name from the UploadItemRef from step 1. 1. Call indexing.datasources.items.index to index the item. Populate the [ItemContent](/cloud-search/docs/reference/rest/v1/indexing.datasources.items#ItemContent) with the UploadItemRef from step 1. For additional information, see Create a content connector using the REST API. Note: This API requires a service account to execute.

request - The metadata request object.

Request parameters:

resourceName - Name of the media that is being downloaded. See ReadRequest.resource_name. Value must have pattern ^.*$.

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

uploadMedia - The media to upload.

Completes with a Media.

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<Media> upload(
  Media request,
  core.String resourceName, {
  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_ = 'v1/media/' + core.Uri.encodeFull('$resourceName');
  } else {
    url_ = '/upload/v1/media/' + core.Uri.encodeFull('$resourceName');
  }

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