insert method

Future<Object> insert(
  1. Object request,
  2. String bucket, {
  3. String? contentEncoding,
  4. String? ifGenerationMatch,
  5. String? ifGenerationNotMatch,
  6. String? ifMetagenerationMatch,
  7. String? ifMetagenerationNotMatch,
  8. String? kmsKeyName,
  9. String? name,
  10. String? predefinedAcl,
  11. String? projection,
  12. String? userProject,
  13. String? $fields,
  14. UploadOptions uploadOptions = commons.UploadOptions.defaultOptions,
  15. Media? uploadMedia,
})

Stores a new object and metadata.

request - The metadata request object.

Request parameters:

bucket - Name of the bucket in which to store the new object. Overrides the provided object metadata's bucket value, if any.

contentEncoding - If set, sets the contentEncoding property of the final object to this value. Setting this parameter is equivalent to setting the contentEncoding metadata property. This can be useful when uploading an object with uploadType=media to indicate the encoding of the content being uploaded.

ifGenerationMatch - Makes the operation conditional on whether the object's current generation matches the given value. Setting to 0 makes the operation succeed only if there are no live versions of the object.

ifGenerationNotMatch - Makes the operation conditional on whether the object's current generation does not match the given value. If no live object exists, the precondition fails. Setting to 0 makes the operation succeed only if there is a live version of the object.

ifMetagenerationMatch - Makes the operation conditional on whether the object's current metageneration matches the given value.

ifMetagenerationNotMatch - Makes the operation conditional on whether the object's current metageneration does not match the given value.

kmsKeyName - Resource name of the Cloud KMS key, of the form projects/my-project/locations/global/keyRings/my-kr/cryptoKeys/my-key, that will be used to encrypt the object. Overrides the object metadata's kms_key_name value, if any.

name - Name of the object. Required when the object metadata is not otherwise provided. Overrides the object metadata's name value, if any. For information about how to URL encode object names to be path safe, see Encoding URI Path Parts.

predefinedAcl - Apply a predefined set of access controls to this object. Possible string values are:

  • "authenticatedRead" : Object owner gets OWNER access, and allAuthenticatedUsers get READER access.
  • "bucketOwnerFullControl" : Object owner gets OWNER access, and project team owners get OWNER access.
  • "bucketOwnerRead" : Object owner gets OWNER access, and project team owners get READER access.
  • "private" : Object owner gets OWNER access.
  • "projectPrivate" : Object owner gets OWNER access, and project team members get access according to their roles.
  • "publicRead" : Object owner gets OWNER access, and allUsers get READER access.

projection - Set of properties to return. Defaults to noAcl, unless the object resource specifies the acl property, when it defaults to full. Possible string values are:

  • "full" : Include all properties.
  • "noAcl" : Omit the owner, acl property.

userProject - The project to be billed for this request. Required for Requester Pays buckets.

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

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<Object> insert(
  Object request,
  core.String bucket, {
  core.String? contentEncoding,
  core.String? ifGenerationMatch,
  core.String? ifGenerationNotMatch,
  core.String? ifMetagenerationMatch,
  core.String? ifMetagenerationNotMatch,
  core.String? kmsKeyName,
  core.String? name,
  core.String? predefinedAcl,
  core.String? projection,
  core.String? userProject,
  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 (contentEncoding != null) 'contentEncoding': [contentEncoding],
    if (ifGenerationMatch != null) 'ifGenerationMatch': [ifGenerationMatch],
    if (ifGenerationNotMatch != null)
      'ifGenerationNotMatch': [ifGenerationNotMatch],
    if (ifMetagenerationMatch != null)
      'ifMetagenerationMatch': [ifMetagenerationMatch],
    if (ifMetagenerationNotMatch != null)
      'ifMetagenerationNotMatch': [ifMetagenerationNotMatch],
    if (kmsKeyName != null) 'kmsKeyName': [kmsKeyName],
    if (name != null) 'name': [name],
    if (predefinedAcl != null) 'predefinedAcl': [predefinedAcl],
    if (projection != null) 'projection': [projection],
    if (userProject != null) 'userProject': [userProject],
    if ($fields != null) 'fields': [$fields],
  };

  core.String url_;
  if (uploadMedia == null) {
    url_ = 'b/' + commons.escapeVariable('$bucket') + '/o';
  } else if (uploadOptions is commons.ResumableUploadOptions) {
    url_ = '/resumable/upload/storage/v1/b/' +
        commons.escapeVariable('$bucket') +
        '/o';
  } else {
    url_ = '/upload/storage/v1/b/' + commons.escapeVariable('$bucket') + '/o';
  }

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