upload method

Future<Document> upload(
  1. Document request, {
  2. String? documentId,
  3. String? requestId,
  4. String? $fields,
  5. UploadOptions uploadOptions = commons.UploadOptions.defaultOptions,
  6. Media? uploadMedia,
})

Creates a new Document resource and ingests the manuscript using media upload or Google Drive.

request - The metadata request object.

Request parameters:

documentId - Optional. The ID to use for the document, which will become the final component of the document's resource name. If not provided, a unique server-generated UUID will be assigned.

requestId - Optional. Idempotency identifier for network retry safety (AIP-155). Must be a valid UUID4 string.

$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 Document.

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<Document> upload(
  Document request, {
  core.String? documentId,
  core.String? requestId,
  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>>{
    'documentId': ?documentId == null ? null : [documentId],
    'requestId': ?requestId == null ? null : [requestId],
    'fields': ?$fields == null ? null : [$fields],
  };

  core.String url_;
  if (uploadMedia == null) {
    url_ = 'v1/documents';
  } else if (uploadOptions is commons.ResumableUploadOptions) {
    url_ = '/resumable/upload/v1/documents';
  } else {
    url_ = '/upload/v1/documents';
  }

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