Skip to content

Instantly share code, notes, and snippets.

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