Skip to content

Instantly share code, notes, and snippets.

@aplater
Forked from erickoledadevrel/downloadFileRange.gs
Created February 20, 2020 13:32
Show Gist options
  • Select an option

  • Save aplater/e15beccacfaa3a98ba6c7dfa397d1040 to your computer and use it in GitHub Desktop.

Select an option

Save aplater/e15beccacfaa3a98ba6c7dfa397d1040 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