Gists
This is a sample script of Node.js for downloading the data and uploading the data to Google Drive with the resumable upload without saving it as a file. The downloaded data is uploaded to Google Drive with the stream.
Sample script
Before you use this, please set the variables of accessToken, url, fileSize, mimeType and filename. In this case, fileSize is required to set because the data is uploaded with the resumable upload.
Gists
This is a sample script for downloading the active sheet in Google Spreadsheet to the local PC as a CSV file and a PDF file when a button on the side bar and the dialog is clicked. This is created with Google Apps Script and HTML&Javascript. In this post, the script of the previous post was modified.

Sample script
Please create new Google Spreadsheet and copy and paste the following scripts to the script editor. And please run openSidebar(). By this, the side bar is opened to the Spreadsheet.
Gists
This is a sample script for downloading Google Spreadsheet to the local PC as a XLSX file and a PDF file when a button on the side bar and the dialog is clicked. This is created with Google Apps Script and HTML&Javascript.

Sample script
Please create new Google Spreadsheet and copy and paste the following scripts to the script editor. And please run openSidebar(). By this, the side bar is opened to the Spreadsheet.
-
v1.0.3 (August 1, 2020)
- When the file size less than the default chunk is downloaded, an error occurred. This bug was removed.
You can see the detail information here https://github.com/tanaikech/DownloadLargeFilesByUrl
Overview
This is a sample script for downloading files from Google Drive by the one time download method.
Description
When you download a file from Google Drive, in generally, the login and the access token are required. If you want to download the file without the authorization for the simple situation, the file is required to be publicly shared. But the file might not be able to be shared publicly, because of various reasons.
You can see the detail information here https://github.com/tanaikech/DownloadLargeFilesByUrl
Overview
DownloadLargeFilesByUrl is a GAS library for downloading large files from URL to Google Drive using Google Apps Script (GAS).
Description
I had been thinking of about whether a large file from an URL can be downloaded to Google Drive using GAS. When I have tried to download such large files, I noticed the following limitations. These limitations are due to the specification of GAS.
- When users download a file from URL using GAS, at the most users, it retrieves the blob using
UrlFetchApp.fetch(url).getBlob() and saves it as a file using DriveApp.createFile(blob). In this case, only files less than 50 MB (52,428,800 bytes) can be created, because of the size limitation of Blob.
- There are a limit executing time for Google Apps Script (GAS). That is 6 min/execution.
- There are a limit of total executing time for running scripts by triggers. That is 90 min/day. (Recently, it became from 60 min/day to 90 min/day.)
When it tries to create the application for downloading the large files, it is required to consider above limitations. On the other hand, there are the following relaxations of quotas by the recent Google’s update.
Gists
This is a sample script for downloading a file using a button of dialog box on Google Docs (Spreadsheet, Document and Slides).
Please use this sample script at script editor on Google Docs (Spreadsheet, Document and Slides). And please set file ID in the script.
FLow :
The flow of this sample script is as follows.
- Run
dialog().
- When users click a download button, retrieve file ID at GAS side.
- Create download URL from the file ID. Download URL and filename are sent to
download(obj) of Javascript.
- Create a tag for downloading and click it at Javascript side.
- By this, users can download the file of file ID.
Code.gs
function dialog() {
var html = HtmlService.createHtmlOutputFromFile('download');
SpreadsheetApp.getUi().showModalDialog(html, 'Sample dialog'); // If you use other Google Docs, please modify here.
}
function getDownloadUrl() {
var id = "### file id ###";
var file = DriveApp.getFileById(id);
return {
url: file.getDownloadUrl().replace("?e=download&gd=true",""),
filename: file.getName()
};
}
download.html
<input type="button" value="download" onclick="getUrl()" />
<script>
function getUrl() {
google.script.run.withSuccessHandler(download).getDownloadUrl();
}
function download(obj) {
var d = document.createElement('a');
d.href = obj.url;
d.download = obj.filename;
d.click();
}
</script>
Gists
This sample script is for downloading files under a specific folder using Node.js. It can download files with Google Docs and others.
This sample supposes as follows. So please confirm it.
- quickstart is used and default quickstart works fine.
In order to use this sample, please carry out as follows.
- Replace
listFiles() of the default quickstart to this sample.
- Set
folderid. This script can retrieve files in the folder with folderid.
- Delete
drive-nodejs-quickstart.json. I think that there is the file at .credentials in your home directory.
- Change the SCOPE from
var SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly']; to var SCOPES = ['https://www.googleapis.com/auth/drive.readonly'];.
- Run script, retrieve the code and authorize.
Script :
function listFiles(auth) {
var folderid = "### folder ID ###"; // Folder ID. This script downloads files in the folder with this folder ID.
var outputExtension = "pdf"; // Extension of output file. This is adapted to only Google Docs.
var outputMimeType = mime.lookup(outputExtension);
var service = google.drive('v3');
service.files.list({
auth: auth,
q: "'" + folderid + "' in parents and trashed=false",
fields: "files(id, name, mimeType)"
}, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
response.files.forEach(function(e){
if (e.mimeType.includes("application/vnd.google-apps")) {
var dlfile = fs.createWriteStream(e.name + "." + outputExtension);
service.files.export({
auth: auth,
fileId: e.id,
mimeType: outputMimeType
}).on('end', function() {
console.log("'%s' was downloaded as %s.", e.name, outputExtension);
}).on('error', function(err) {
console.error(err);
return process.exit();
}).pipe(dlfile);
} else {
var dlfile = fs.createWriteStream(e.name);
service.files.get({
auth: auth,
fileId: e.id,
alt: 'media'
}).on('end', function() {
console.log("'%s' was downloaded as %s.", e.name, mime.extension(e.mimeType));
}).on('error', function(err) {
console.error(err);
return process.exit();
}).pipe(dlfile);
}
});
});
}
Gists
When the shared files on Google Drive is downloaded, it is necessary to change the download method by the file size. The boundary of file size when the method is changed is about 40MB.
File size < 40MB
CURL
filename="### filename ###"
fileid="### file ID ###"
curl -L -o ${filename} "https://drive.google.com/uc?export=download&id=${fileid}"
File size > 40MB
When it tries to download the file with more than 40MB, Google says to download from following URL.
Gist
This is a sample script for downloading files from Google Drive under no authorization using browser. By using this sample, you can make other users download files from your Google Drive. Even if the other users are not Google users, they can download the files.
Demo

This is a demonstration for downloading files from Google Drive under no authorization using browser. From the top document, You can see that an user who is not owner of Google Drive is downloading files.