创建云端硬盘文件的快捷方式

快捷方式是指链接到 Google 云端硬盘中其他文件或文件夹的文件。 快捷方式具有以下特征:

  • application/vnd.google-apps.shortcut MIME 类型。如需更多信息 请参阅 Google Workspace 和Google 云端硬盘支持的 MIME 类型

  • 快捷方式的 ACL 将继承父级的 ACL。快捷方式的 ACL 无法直接更改

  • 指向目标文件或文件夹的 targetId,也称为 “target”

  • targetMimeType,表示目标的 MIME 类型。通过 targetMimeType 用于确定要显示的类型图标。目标的 将快捷方式复制到 targetMimeType 字段后, 创建。

  • targetIdtargetMimeType 字段是 shortcutDetails 的一部分 字段。

  • 一个快捷方式只能有一个父级。如果其他文件中需要快捷方式文件 云端硬盘位置,可将快捷方式文件复制到 。

  • 当目标被删除时,或当前用户失去对 target,则用户指向目标的快捷方式会中断。

  • 快捷方式的标题可以与目标不同。快捷方式为 则该目标的名称将用作快捷方式的标题。更新后 快捷方式的标题和目标标题可以更改 相互独立。如果目标的名称发生更改,则使用之前创建的快捷方式 旧标题。

  • 快捷方式的 MIME 类型可能会过时。blob 文件的 MIME 是很少的 其他类型的修订版本上传时,类型会发生更改, 指向更新文件的快捷方式会保留原始 MIME 类型。对于 例如,如果您将一个 JPG 文件上传到云端硬盘,然后将 AVI 修订版本,云端硬盘识别更改并更新 实际文件的缩略图不过,快捷方式仍采用 JPG 格式 缩略图。

  • Google 账号数据中 导出 也称为“Google 导出”,快捷方式以 Netscape 的形式表示 书签文件。

有关详情,请参阅查找文件和文件夹和 Google 云端硬盘 快捷方式 ,了解所有最新动态。

创建快捷方式

如要创建快捷方式,请将 MIME 类型设为 application/vnd.google-apps.shortcut,请将 targetId 设置为文件或文件夹 相应快捷方式应链接到该快捷方式,并调用 files.create 以创建快捷方式。

以下示例展示了如何使用客户端库创建快捷方式:

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:此快捷方式的名称。

默认情况下,系统会在当前用户的“我的 仅为以下文件夹的文件或文件夹创建云端硬盘和快捷方式: 当前用户有权访问的

搜索快捷方式

如需搜索快捷方式,请使用查询字符串 qfiles.list,用于过滤快捷方式 return。

mimeType operator values

其中:

  • query_term 是要搜索的查询字词或字段。要查看查询,请执行以下操作: 可用于过滤共享云端硬盘的字词,请参阅搜索查询 条款
  • operator 指定查询字词的条件。要查看哪些 运算符,请参阅查询运算符
  • values 是您要用于过滤搜索的具体值 结果。

例如,以下查询字符串过滤搜索,以返回所有 电子表格文件的快捷方式:

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