-
-
Save aplater/e15beccacfaa3a98ba6c7dfa397d1040 to your computer and use it in GitHub Desktop.
Downloading a portion of a Drive file in Apps Script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function downloadFileRange(fileId, startByte, endByte) { | |
| // Mention DriveApp in a comment to ensure the Drive scope is requested. | |
| // DriveApp.getRootFolder(); | |
| var url = 'https://www.googleapis.com/drive/v3/files/' + | |
| fileId + '?alt=media'; | |
| var response = UrlFetchApp.fetch(url, { | |
| headers: { | |
| Authorization: 'Bearer ' + ScriptApp.getOAuthToken(), | |
| Range: 'bytes=' + startByte + '-' + endByte | |
| } | |
| }); | |
| // Assuming it's text content. | |
| return response.getContentText(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment