I have a case where:
- I have a Drive-folderId and the folder contains some zip files. And the zip files further contains some .docx files.
- Next, I want to search for a specific .docx in any of the zip files in the said folder.(say the file is
A.docx
) - If found, I have to send that file,
A.docx
, as GMail Attachment using GMail API (I can use file.getWebViewLink() for this)
The problem is at the 2 point. (Extracting multiple zip files and then searching for files)
My Options
- Use Apps Script API to extract the files of zip files and then search for
A.docx
. - Download all the zip files from the folder and extract it locally and then find the
A.docx
and then send it as attachments in Gmail API.
Now, kindly suggest which will be the better way to go?
Also, found this article to use Google-Apps-Script. Can I get some articles to refer to for GAS as the Google documentation is pretty limited? Thanks!
EDIT
Java Code:
StringBuilder sb = new StringBuilder();
InputStreamReader in = null;
URL url = new URL("https://script.google.com/a/<id>/exec?param1=HelloWorld");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
if (connection.getInputStream() != null) {
System.out.println(connection.getInputStream());
in = new InputStreamReader(connection.getInputStream(),Charset.defaultCharset());
BufferedReader bufferedReader = new BufferedReader(in);
if (bufferedReader != null) {
int cp;
while ((cp = bufferedReader.read()) != -1) {
sb.append((char) cp);
}
bufferedReader.close();
}
}
System.out.println(sb.toString());
GAS Code:
function doGet(e) {
var params = JSON.stringify(e);
var param = e.queryString;
return param+"Received";
}
I want to fetch returned String output
but conn.getInputStream()
currently returns an empty html form. What am I doing wrong here?
Current Scenario
After running both the fore-mentioned codes(Java and GAS), when I sysout the connection.getInputStream()
, all I get in console is an HTML markup with title Google - Sign in
. What I conclude is that it is asking for o-auth. But should a script ask for it? How to proceed further from this?
What I simply want is pass some parameters such as folderId
and fileName such as A
and to my GAScript doGet(e)
, I want to traverse the files of the passed folderId and then extract all the zipped files to find A.docx
. If found, I want to unzip it in a seperate folder and hence attach it in a mail(I can handle the mailing part, just want to extract the required docx).