建立雲端硬碟檔案的捷徑

捷徑是連結至 Google 雲端硬碟中其他檔案或資料夾的檔案。 快速鍵具有以下特性:

  • application/vnd.google-apps.shortcut MIME 類型。詳情請參閱「Google Workspace 和 Google 雲端硬碟支援的 MIME 類型」一文。

  • 捷徑的 ACL 會繼承父項的 ACL。您無法直接變更捷徑的 ACL。

  • 指向目標檔案或資料夾的 targetId,也稱為「目標」。

  • targetMimeType,表示目標的 MIME 類型。targetMimeType 是用於決定要顯示的類型圖示。建立捷徑時,目標的 MIME 類型會複製到 targetMimeType 欄位。

  • targetIdtargetMimeType 欄位是檔案資源中 shortcutDetails 欄位的一部分。

  • 每個捷徑只能有一個父項。如果其他雲端硬碟位置需要捷徑檔案,可以將捷徑檔案複製到其他位置。

  • 當目標刪除或目前使用者失去目標存取權時,使用者的捷徑會指向目標中斷點。

  • 捷徑的標題可以與目標不同。建立捷徑時,目標的標題會做為捷徑的標題。建立後,捷徑的標題和目標標題可以獨立變更。如果目標名稱有所變更,先前建立的捷徑會保留舊的標題。

  • 捷徑的 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:此捷徑的名稱。

根據預設,系統會在目前使用者的「我的雲端硬碟」上建立捷徑,且系統只會針對目前使用者可存取的檔案或資料夾建立捷徑。

搜尋快速鍵

如要搜尋捷徑,請使用查詢字串 q 搭配 files.list,篩選要傳回的快速鍵。

mimeType operator values

在此情況下:

  • query_term 是要搜尋的查詢字詞或欄位。如要查看可用於篩選共用雲端硬碟的查詢字詞,請參閱搜尋查詢條款
  • 「運算子」會指定查詢字詞的條件。如要查看每個查詢字詞可與哪些運算子搭配使用,請參閱查詢運算子
  • 是您想要用來篩選搜尋結果的特定值。

例如,以下查詢字串會篩選搜尋,傳回試算表檔案中的所有捷徑:

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