upload method

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

Uploads an asset.

Returns the ID of the newly uploaded asset if successful. The asset file size should be no more than 10 MB for images, 200 MB for ZIP files, and 1 GB for videos. Must be used within the [multipart media upload process](/display-video/api/guides/how-tos/upload#multipart). Examples using provided client libraries can be found in our [Creating Creatives guide](/display-video/api/guides/creating-creatives/overview#upload_an_asset).

request - The metadata request object.

Request parameters:

advertiserId - Required. The ID of the advertiser this asset belongs to. Value must have pattern ^\[^/\]+$.

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

uploadMedia - The media to upload.

Completes with a CreateAssetResponse.

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<CreateAssetResponse> upload(
  CreateAssetRequest request,
  core.String advertiserId, {
  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_ =
        'v2/advertisers/' + core.Uri.encodeFull('$advertiserId') + '/assets';
  } else {
    url_ = '/upload/v2/advertisers/' +
        core.Uri.encodeFull('$advertiserId') +
        '/assets';
  }

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