update method

Future<File> update(
  1. File request,
  2. String fileId, {
  3. String? addParents,
  4. bool? convert,
  5. bool? enforceSingleParent,
  6. String? includeLabels,
  7. String? includePermissionsForView,
  8. String? modifiedDateBehavior,
  9. bool? newRevision,
  10. bool? ocr,
  11. String? ocrLanguage,
  12. bool? pinned,
  13. String? removeParents,
  14. bool? setModifiedDate,
  15. bool? supportsAllDrives,
  16. bool? supportsTeamDrives,
  17. String? timedTextLanguage,
  18. String? timedTextTrackName,
  19. bool? updateViewedDate,
  20. bool? useContentAsIndexableText,
  21. String? $fields,
  22. UploadOptions uploadOptions = commons.UploadOptions.defaultOptions,
  23. Media? uploadMedia,
})

Updates a file's metadata and/or content.

When calling this method, only populate fields in the request that you want to modify. When updating fields, some fields might be changed automatically, such as modifiedDate. This method supports patch semantics. This method supports an * / upload* URI and accepts uploaded media with the following characteristics: - Maximum file size: 5,120 GB

  • Accepted Media MIME types:* / * Note: Specify a valid MIME type, rather than the literal * / * value. The literal * / * is only used to indicate that any valid MIME type can be uploaded. For more information on uploading files, see [Upload file data](/drive/api/guides/manage-uploads).

request - The metadata request object.

Request parameters:

fileId - The ID of the file to update.

addParents - Comma-separated list of parent IDs to add.

convert - Deprecated: This parameter has no function.

enforceSingleParent - Deprecated: Adding files to multiple folders is no longer supported. Use shortcuts instead.

includeLabels - A comma-separated list of IDs of labels to include in the labelInfo part of the response.

includePermissionsForView - Specifies which additional view's permissions to include in the response. Only published is supported.

modifiedDateBehavior - Determines the behavior in which modifiedDate is updated. This overrides setModifiedDate. Possible string values are:

  • "fromBody" : Set modifiedDate to the value provided in the body of the request. No change if no value was provided.
  • "fromBodyIfNeeded" : Set modifiedDate to the value provided in the body of the request depending on other contents of the update.
  • "fromBodyOrNow" : Set modifiedDate to the value provided in the body of the request, or to the current time if no value was provided.
  • "noChange" : Maintain the previous value of modifiedDate.
  • "now" : Set modifiedDate to the current time.
  • "nowIfNeeded" : Set modifiedDate to the current time depending on contents of the update.

newRevision - Whether a blob upload should create a new revision. If false, the blob data in the current head revision is replaced. If true or not set, a new blob is created as head revision, and previous unpinned revisions are preserved for a short period of time. Pinned revisions are stored indefinitely, using additional storage quota, up to a maximum of 200 revisions. For details on how revisions are retained, see the Drive Help Center.

ocr - Whether to attempt OCR on .jpg, .png, .gif, or .pdf uploads.

ocrLanguage - If ocr is true, hints at the language to use. Valid values are BCP 47 codes.

pinned - Whether to pin the new revision. A file can have a maximum of 200 pinned revisions.

removeParents - Comma-separated list of parent IDs to remove.

setModifiedDate - Whether to set the modified date using the value supplied in the request body. Setting this field to true is equivalent to modifiedDateBehavior=fromBodyOrNow, and false is equivalent to modifiedDateBehavior=now. To prevent any changes to the modified date set modifiedDateBehavior=noChange.

supportsAllDrives - Whether the requesting application supports both My Drives and shared drives.

supportsTeamDrives - Deprecated: Use supportsAllDrives instead.

timedTextLanguage - The language of the timed text.

timedTextTrackName - The timed text track name.

updateViewedDate - Whether to update the view date after successfully updating the file.

useContentAsIndexableText - Whether to use the content as indexable text.

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

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<File> update(
  File request,
  core.String fileId, {
  core.String? addParents,
  core.bool? convert,
  core.bool? enforceSingleParent,
  core.String? includeLabels,
  core.String? includePermissionsForView,
  core.String? modifiedDateBehavior,
  core.bool? newRevision,
  core.bool? ocr,
  core.String? ocrLanguage,
  core.bool? pinned,
  core.String? removeParents,
  core.bool? setModifiedDate,
  core.bool? supportsAllDrives,
  core.bool? supportsTeamDrives,
  core.String? timedTextLanguage,
  core.String? timedTextTrackName,
  core.bool? updateViewedDate,
  core.bool? useContentAsIndexableText,
  core.String? $fields,
  commons.UploadOptions uploadOptions = commons.UploadOptions.defaultOptions,
  commons.Media? uploadMedia,
}) async {
  final body_ = convert_1.json.encode(request);
  final queryParams_ = <core.String, core.List<core.String>>{
    if (addParents != null) 'addParents': [addParents],
    if (convert != null) 'convert': ['${convert}'],
    if (enforceSingleParent != null)
      'enforceSingleParent': ['${enforceSingleParent}'],
    if (includeLabels != null) 'includeLabels': [includeLabels],
    if (includePermissionsForView != null)
      'includePermissionsForView': [includePermissionsForView],
    if (modifiedDateBehavior != null)
      'modifiedDateBehavior': [modifiedDateBehavior],
    if (newRevision != null) 'newRevision': ['${newRevision}'],
    if (ocr != null) 'ocr': ['${ocr}'],
    if (ocrLanguage != null) 'ocrLanguage': [ocrLanguage],
    if (pinned != null) 'pinned': ['${pinned}'],
    if (removeParents != null) 'removeParents': [removeParents],
    if (setModifiedDate != null) 'setModifiedDate': ['${setModifiedDate}'],
    if (supportsAllDrives != null)
      'supportsAllDrives': ['${supportsAllDrives}'],
    if (supportsTeamDrives != null)
      'supportsTeamDrives': ['${supportsTeamDrives}'],
    if (timedTextLanguage != null) 'timedTextLanguage': [timedTextLanguage],
    if (timedTextTrackName != null)
      'timedTextTrackName': [timedTextTrackName],
    if (updateViewedDate != null) 'updateViewedDate': ['${updateViewedDate}'],
    if (useContentAsIndexableText != null)
      'useContentAsIndexableText': ['${useContentAsIndexableText}'],
    if ($fields != null) 'fields': [$fields],
  };

  core.String url_;
  if (uploadMedia == null) {
    url_ = 'files/' + commons.escapeVariable('$fileId');
  } else if (uploadOptions is commons.ResumableUploadOptions) {
    url_ = '/resumable/upload/drive/v2/files/' +
        commons.escapeVariable('$fileId');
  } else {
    url_ = '/upload/drive/v2/files/' + commons.escapeVariable('$fileId');
  }

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