Loads a Drive file by its file ID.
class DriveApp method .getFileById()
DriveApp is the Apps Script service.
.getFileById() is the method name you will see after a dot in your code.
What it does
Why it's used
- Open a PDF, image, or doc when you only stored the Drive ID.
- Process attachments saved to known file IDs.
Common errors
- Forgetting parentheses on getFileById. Write DriveApp.getFileById(), not DriveApp.getFileById or getFileById by itself.
- Skipping dots between chained calls. Each step needs a dot, like DriveApp.getFileById(id).getFileById().
- Adding spaces where they do not belong. Write DriveApp.getFileById(), not DriveApp .getFileById(), DriveApp.getFileById (), or DriveApp . getFileById().
- Wrong capitalization. Use DriveApp and getFileById, not driveapp or getfilebyid.
1 Snippets using this method
Explore
Related methods
-
.getFolderById()
Loads a Drive folder by its folder ID.
-
.getFilesByName()
Finds files in Drive that match a given name.
-
.searchFiles()
Searches Drive files using a query string.
-
.addFile()
Moves a file into a folder.
-
.getUrl()
Returns the web link to open a file or folder.
More Apps Script
1 Better Sheets tutorials
Automatic Weekly Backup of Google Sheets
Related blog posts
Written guides about DriveApp.getFileById().