insert method

Future<File> insert(
  1. File request, {
  2. bool? convert,
  3. bool? enforceSingleParent,
  4. String? includeLabels,
  5. String? includePermissionsForView,
  6. bool? ocr,
  7. String? ocrLanguage,
  8. bool? pinned,
  9. bool? supportsAllDrives,
  10. bool? supportsTeamDrives,
  11. String? timedTextLanguage,
  12. String? timedTextTrackName,
  13. bool? useContentAsIndexableText,
  14. String? visibility,
  15. String? $fields,
  16. UploadOptions uploadOptions = commons.UploadOptions.defaultOptions,
  17. Media? uploadMedia,
})

Inserts a new 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:* / * 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). Apps creating shortcuts with files.insert must specify the MIME type application/vnd.google-apps.shortcut. Apps should specify a file extension in the title property when inserting files with the API. For example, an operation to insert a JPEG file should specify something like "title": "cat.jpg" in the metadata. Subsequent GET requests include the read-only fileExtension property populated with the extension originally specified in the title 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 title. 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:

convert - Whether to convert this file to the corresponding Docs Editors format.

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

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.

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 head revision of the uploaded file. A file can have a maximum of 200 pinned revisions.

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.

useContentAsIndexableText - Whether to use the content as indexable text.

visibility - The visibility of the new file. This parameter is only relevant when convert=false. Possible string values are:

  • "DEFAULT" : The visibility of the new file is determined by the user's default visibility/sharing policies.
  • "PRIVATE" : The new file will be visible to only the owner.

$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> insert(
  File request, {
  core.bool? convert,
  core.bool? enforceSingleParent,
  core.String? includeLabels,
  core.String? includePermissionsForView,
  core.bool? ocr,
  core.String? ocrLanguage,
  core.bool? pinned,
  core.bool? supportsAllDrives,
  core.bool? supportsTeamDrives,
  core.String? timedTextLanguage,
  core.String? timedTextTrackName,
  core.bool? useContentAsIndexableText,
  core.String? visibility,
  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 (convert != null) 'convert': ['${convert}'],
    if (enforceSingleParent != null)
      'enforceSingleParent': ['${enforceSingleParent}'],
    if (includeLabels != null) 'includeLabels': [includeLabels],
    if (includePermissionsForView != null)
      'includePermissionsForView': [includePermissionsForView],
    if (ocr != null) 'ocr': ['${ocr}'],
    if (ocrLanguage != null) 'ocrLanguage': [ocrLanguage],
    if (pinned != null) 'pinned': ['${pinned}'],
    if (supportsAllDrives != null)
      'supportsAllDrives': ['${supportsAllDrives}'],
    if (supportsTeamDrives != null)
      'supportsTeamDrives': ['${supportsTeamDrives}'],
    if (timedTextLanguage != null) 'timedTextLanguage': [timedTextLanguage],
    if (timedTextTrackName != null)
      'timedTextTrackName': [timedTextTrackName],
    if (useContentAsIndexableText != null)
      'useContentAsIndexableText': ['${useContentAsIndexableText}'],
    if (visibility != null) 'visibility': [visibility],
    if ($fields != null) 'fields': [$fields],
  };

  core.String url_;
  if (uploadMedia == null) {
    url_ = 'files';
  } else if (uploadOptions is commons.ResumableUploadOptions) {
    url_ = '/resumable/upload/drive/v2/files';
  } else {
    url_ = '/upload/drive/v2/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>);
}