download method

Future<Object> download(
  1. String name, {
  2. String? mimeType,
  3. String? $fields,
  4. DownloadOptions downloadOptions = commons.DownloadOptions.metadata,
})

Gets an attachment.

To download attachment media via REST requires the alt=media query parameter. Returns a 400 bad request error if attachment media is not available in the requested MIME type.

Request parameters:

name - Required. The name of the attachment. Value must have pattern ^notes/\[^/\]+/attachments/\[^/\]+$.

mimeType - The IANA MIME type format requested. The requested MIME type must be one specified in the attachment.mime_type. Required when downloading attachment media and ignored otherwise.

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

downloadOptions - Options for downloading. A download can be either a Metadata (default) or Media download. Partial Media downloads are possible as well.

Completes with a

  • Attachment for Metadata downloads (see downloadOptions).

  • commons.Media for Media downloads (see downloadOptions).

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<core.Object> download(
  core.String name, {
  core.String? mimeType,
  core.String? $fields,
  commons.DownloadOptions downloadOptions = commons.DownloadOptions.metadata,
}) async {
  final queryParams_ = <core.String, core.List<core.String>>{
    if (mimeType != null) 'mimeType': [mimeType],
    if ($fields != null) 'fields': [$fields],
  };

  final url_ = 'v1/' + core.Uri.encodeFull('$name');

  final response_ = await _requester.request(
    url_,
    'GET',
    queryParams: queryParams_,
    downloadOptions: downloadOptions,
  );
  if (downloadOptions.isMetadataDownload) {
    return Attachment.fromJson(
        response_ as core.Map<core.String, core.dynamic>);
  } else {
    return response_ as commons.Media;
  }
}