create method

Future<File> create(
  1. File request, {
  2. bool? enforceSingleParent,
  3. bool? ignoreDefaultVisibility,
  4. String? includeLabels,
  5. String? includePermissionsForView,
  6. bool? keepRevisionForever,
  7. String? ocrLanguage,
  8. bool? supportsAllDrives,
  9. bool? supportsTeamDrives,
  10. bool? useContentAsIndexableText,
  11. String? $fields,
  12. UploadOptions uploadOptions = commons.UploadOptions.defaultOptions,
  13. Media? uploadMedia,
})

Creates a file.

For more information, see [Create and manage files](/workspace/drive/api/guides/create-file). This method supports an

  • / upload* URI and accepts uploaded media with the following characteristics: - Maximum file size: 5,120 GB - Accepted Media MIME types: * / * (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, see \[Google Workspace and Google Drive supported MIME types\](/workspace/drive/api/guides/mime-types).) For more information on uploading files, see \[Upload file data\](/workspace/drive/api/guides/manage-uploads). Apps creating shortcuts with thecreatemethod must specify the MIME typeapplication/vnd.google-apps.shortcut. Apps should specify a file extension in the nameproperty when inserting files with the API. For example, an operation to insert a JPEG file should specify something like"name": "cat.jpg"in the metadata. SubsequentGETrequests include the read-onlyfileExtensionproperty populated with the extension originally specified in thename` property. When a Google Drive user requests to download a file, or when the file is downloaded through the sync client, Drive builds a full filename (with extension) based on the name. In cases where the extension is missing, Drive attempts to determine the extension based on the file's MIME type.

request - The metadata request object.

Request parameters:

enforceSingleParent - Deprecated: Creating files in multiple folders is no longer supported.

ignoreDefaultVisibility - Whether to ignore the domain's default visibility settings for the created file. Domain administrators can choose to make all uploaded files visible to the domain by default; this parameter bypasses that behavior for the request. Permissions are still inherited from parent folders.

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.

keepRevisionForever - Whether to set the keepForever field in the new head revision. This is only applicable to files with binary content in Google Drive. Only 200 revisions for the file can be kept forever. If the limit is reached, try deleting pinned revisions.

ocrLanguage - A language hint for OCR processing during image import (ISO 639-1 code).

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

supportsTeamDrives - Deprecated: Use supportsAllDrives instead.

useContentAsIndexableText - Whether to use the uploaded 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> create(
  File request, {
  core.bool? enforceSingleParent,
  core.bool? ignoreDefaultVisibility,
  core.String? includeLabels,
  core.String? includePermissionsForView,
  core.bool? keepRevisionForever,
  core.String? ocrLanguage,
  core.bool? supportsAllDrives,
  core.bool? supportsTeamDrives,
  core.bool? useContentAsIndexableText,
  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 (enforceSingleParent != null)
      'enforceSingleParent': ['${enforceSingleParent}'],
    if (ignoreDefaultVisibility != null)
      'ignoreDefaultVisibility': ['${ignoreDefaultVisibility}'],
    if (includeLabels != null) 'includeLabels': [includeLabels],
    if (includePermissionsForView != null)
      'includePermissionsForView': [includePermissionsForView],
    if (keepRevisionForever != null)
      'keepRevisionForever': ['${keepRevisionForever}'],
    if (ocrLanguage != null) 'ocrLanguage': [ocrLanguage],
    if (supportsAllDrives != null)
      'supportsAllDrives': ['${supportsAllDrives}'],
    if (supportsTeamDrives != null)
      'supportsTeamDrives': ['${supportsTeamDrives}'],
    if (useContentAsIndexableText != null)
      'useContentAsIndexableText': ['${useContentAsIndexableText}'],
    if ($fields != null) 'fields': [$fields],
  };

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

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