Создать ярлык для файла на Диске

Shortcuts are files that link to other files or folders on Google Drive. Shortcuts have these characteristics:

  • An application/vnd.google-apps.shortcut MIME type. For more information, see Google Workspace & Google Drive supported MIME types .

  • The ACL for a shortcut inherits the ACL of the parent. The shortcut's ACL cannot be changed directly.

  • A targetId pointing to the target file or folder, also referred to as the "target."

  • Параметр targetMimeType указывает MIME-тип целевого объекта. Параметр targetMimeType используется для определения типа отображаемой иконки. MIME-тип целевого объекта копируется в поле targetMimeType при создании ярлыка.

  • The targetId and targetMimeType fields are part of the shortcutDetails field within the file resource.

  • A shortcut can only have one parent. If a shortcut file is required in other Drive locations, the shortcut file can be copied to the additional locations.

  • When the target is deleted, or when the current user loses access to the target, the user's shortcut pointing to the target breaks.

  • Заголовок ярлыка может отличаться от заголовка целевого объекта. При создании ярлыка в качестве заголовка используется заголовок целевого объекта. После создания заголовок ярлыка и заголовок целевого объекта можно изменять независимо друг от друга. Если изменяется имя целевого объекта, ранее созданные ярлыки сохраняют старый заголовок.

  • MIME-тип ярлыка может устареть. Хотя это и редкость, MIME-тип файла blob изменяется при загрузке версии другого типа, но любые ярлыки, указывающие на обновленный файл, сохраняют исходный MIME-тип. Например, если вы загрузите файл JPG в Google Диск, а затем загрузите версию AVI, Google Диск обнаружит изменение и обновит миниатюру для фактического файла. Однако ярлык по-прежнему будет иметь миниатюру JPG.

  • In Google Account Data Export also known as Google Takeout, shortcuts are represented as Netscape bookmark files containing links to the target.

For more information, see Find files & folders with Google Drive shortcuts .

Создать ярлык

Чтобы создать ярлык, установите MIME-тип на application/vnd.google-apps.shortcut , укажите targetId на файл или папку, на которую должен ссылаться ярлык, и вызовите files.create для создания ярлыка.

The following examples show how to create a shortcut using a client library:

Python

file_metadata = {
    'name': 'FILE_NAME',
    'mimeType': 'text/plain'
}
file = drive_service.files().create(body=file_metadata, fields='id').execute()
print('File ID: %s' % file.get('id'))
shortcut_metadata = {
     'Name': 'SHORTCUT_NAME',
     'mimeType': 'application/vnd.google-apps.shortcut',
     'shortcutDetails': {
        'targetId': file.get('id')
     }
}
shortcut = drive_service.files().create(body=shortcut_metadata,
                                    fields='id,shortcutDetails').execute()
print('File ID: %s, Shortcut Target ID: %s, Shortcut Target MIME type: %s' % (
    shortcut.get('id'),
    shortcut.get('shortcutDetails').get('targetId'),
    shortcut.get('shortcutDetails').get('targetMimeType')))

Node.js

var fileMetadata = {
  'name': 'FILE_NAME',
  'mimeType': 'text/plain'
};
drive.files.create({
  'resource': fileMetadata,
  'fields': 'id'
}, function (err, file) {
  if (err) {
    // Handle error
    console.error(err);
  } else {
    console.log('File Id: ' + file.id);
    shortcutMetadata = {
      'name': 'SHORTCUT_NAME',
      'mimeType': 'application/vnd.google-apps.shortcut'
      'shortcutDetails': {
        'targetId': file.id
      }
    };
    drive.files.create({
      'resource': shortcutMetadata,
      'fields': 'id,name,mimeType,shortcutDetails'
    }, function(err, shortcut) {
      if (err) {
        // Handle error
        console.error(err);
      } else {
        console.log('Shortcut Id: ' + shortcut.id +
                    ', Name: ' + shortcut.name +
                    ', target Id: ' + shortcut.shortcutDetails.targetId +
                    ', target MIME type: ' + shortcut.shortcutDetails.targetMimeType);
      }
    }
  }
});

Замените следующее:

  • FILE_NAME : имя файла, для которого требуется создать ярлык.
  • SHORTCUT_NAME : имя для этого сочетания клавиш.

By default, the shortcut is created on the current user's My Drive and shortcuts are only created for files or folders for which the current user has access.

Найти короткий путь

To search for a shortcut, use the query string q with files.list to filter the shortcuts to return.

mimeType operator values

Где:

  • query_term is the query term or field to search upon. To view the query terms that can be used to filter shared drives, refer to Search query terms .
  • operator specifies the condition for the query term. To view which operators you can use with each query term, refer to Query operators .
  • values are the specific values you want to use to filter your search results.

For example, the following query string filters the search to return all shortcuts to spreadsheet files:

q: mimeType='application/vnd.google-apps.shortcut' AND shortcutDetails.targetMimeType='application/vnd.google-apps.spreadsheet'