Created
August 9, 2018 16:22
-
-
Save erickoledadevrel/4659c64dd816e00a60c3ddd38be8e8e9 to your computer and use it in GitHub Desktop.
Downloading a portion of a Drive file in Apps Script.
This file contains 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