捷徑是連結到 Google 雲端硬碟中其他檔案或資料夾的檔案。捷徑具有下列特性:
application/vnd.google-apps.shortcut
MIME 類型。捷徑的 ACL 會繼承父項的 ACL。捷徑的 ACL 無法直接變更。
指向目標檔案或資料夾的
targetId
,也稱為「目標」。表示目標 MIME 類型的
targetMimeType
。targetMimeType
是用於決定要顯示的類型圖示。建立捷徑時,目標的 MIME 類型會複製到targetMimeType
欄位。targetId
和targetMimeType
欄位是 Files 資源內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」是要搜尋的字詞或欄位。如要查看可用於篩選共用雲端硬碟的查詢字詞,請參閱搜尋查詢字詞。
- operator 會指定查詢字詞的條件。如要查看每個查詢字詞可使用哪些運算子,請參閱查詢運算子。
- 「values」是您要用來篩選搜尋結果的特定值。
例如,下列查詢字串會篩選搜尋,以傳回試算表檔案的所有捷徑:
q: mimeType=’application/vnd.google-apps.shortcut’ AND shortcutDetails.targetMimeType=‘application/vnd.google-apps.spreadsheet’