I have written the following Google Apps script, which logs the file names and generates direct download links for the files. So far it is working perfectly.
function SearchFiles() {
var searchFor ='title contains "Letter"';
var names =[];
var fileIds=[];
var files = DriveApp.searchFiles(searchFor);
while (files.hasNext()) {
var file = files.next();
var fileId = file.getId();// To get FileId of the file
fileIds.push(fileId);
var name = file.getName();
names.push(name);
}
for (var i=0;i<names.length;i++){
Logger.log(names[i]);
Logger.log("https://drive.google.com/uc?export=download&id=" + fileIds[i]);
}
}
The Log is like this:
[16-02-04 16:29:27:794 IST] Letter to SRL for Laboratory
[16-02-04 16:29:27:795 IST] https://drive.google.com/uc?export=download& id=1wTDiv7jensErQl2CODxkTb-tYAvv3vDYPGDECEPrXm
[16-02-04 16:29:27:796 IST] Letters_Nirvedanandaji_I.docx
[16-02-04 16:29:27:797 IST] https://drive.google.com/uc?export=download&id=0B_NmiOlCM-VTa3VrNjF0NE9iNWRQODNOME90VGF3WUV2OW5
Now the questions are:
- I want the search term (var searchFor) to be given by user.
- Say the search term is '1234.doc' then the user should be presented with the generated download link. I shall make sure that the search term returns unique value.
- Anyone should be able to use the script (without any authentication)
First you need a
doGet()
function in a script file, which usually goes in:Code
Then you need the main HTML form, often named:
Index
JS_MainPageCode:
If you want to have CSS styling in a separate file, then create an HTML file with
<style></style>
tags, and then use templated HTML to include the seperate file into the Index file.In the example above, the Index file is templated HTML, with lines: