How to create Google Sheets file when CSV file is downloaded - google-apps-script

When a user downloads a CSV file from an arbitrary site, I would like to be informed of this event and automatically upload the same file as a Google Sheets file. Is this possible or would this be violating a fundamental browser security concept?
The CSV file in question does not have a URL, but is created on the fly by the arbitrary web site, when the user clicks a button. An example would be the user's list of financial transactions at a bank web site.
I am not new to Google Apps/Drive but I am new to Google Apps Script.

There is no way to detect that kind of events.
I can't even imagine a function that would allow for automatic file upload of a local file... don't forget Google Apps Script is a server based environment.

Related

Allow Anyone to Upload Files Directly to my Google Drive

I would like to allow my students to send me one or more files directly to my google drive via a form where they would just enter their name and choose the file(s) to send (drag and drop would be great). A folder with their name would be created in a specific folder on my drive and a warning email would be sent to me. Do you think this is feasible with google script? Thanks in advance.
An example here but paying ...
I've checked and Google Forms already allows for a File Upload kind of question (with drag and drop too).
It automatically creates a folder in your Google Drive (altough it doesnt create a folder for every student) (example here) and in the spreadsheet that it automatically generates there is a permanent link to that file (example here).
If that's not what you are looking for and you need the 'Folder per student' feature then yes, you can use google apps script to move files in folders quite easily.

Password Protection for Exported Data from Google Sheet

I saved my data Google Sheet, I can limit access to this data with Sharing feature available at all Google Docs (Sheet). Is there any solution for me to protect exported document from Google Docs (and Sheet)?.
What I can think of right now, password protection on file level as we can found at Microsoft Excel file. I am okay if I need to do some coding in Google Script found at GSuite.
Answer:
Unfortunately there is no way of programmatically setting a password of an exported Drive File.
More Information:
The only programmatic export method of the G Suite APIs is the Files: export method of the Drive API. This end point does not have a way of setting a password to protect the exported file.
Exported files also can not be of a Google Drive File MIME Type and so you can not set a password like one would be able to using the Protect File menu item for web-app deployed Sheet.
This is therefore, sadly, impossible to do. The password protection would have to be set manually on the host machine after export.
References:
Google Drive API Files: export method
Google Drive File MIME Types

Programatically retrieve files uploaded to a Google Form

Looking to automate the processing of data in a spreadsheet generated by google forms; specifically, I want to attach the files uploaded to the form to outgoing emails as attachments. The files can be synced to a local folder for the program to access, but the google form only has a url for each uploaded file.
What would be the most efficient way to determine which of the files uploaded correspond with each form submission and its corresponding link?
Edit: my research indicates that I may be able to use an identifier from the url to see which document it is through an apps api. Another thought was to scrape the html from the linked webpage and then to glean the file name from somewhere in the html here it hopefully occurs with regularity.
Then I could use the filename to construct a filepath to the synced folder on my local machine or would it be better to use the drive api to manipulate the file into an email attachment?

Google Apps Script - publish google documents and read urls

I'm new to Google apps script.
I can create a number of documents in Google Drive via a script and add content.
I would also like to publish them via a script and record the published URL. Is this possible?
I can see an old answer from 2012
"Publish to the web" for Document in Google Apps Script?
You can create all your content in a publicly shared folder, then once you have the folder's ID, you can create a straightforward base URL (e.g. https://googledrive.com/host/[folder ID]/) and simply append the newly created file names. I asked a question related to this topic a few days ago.
Conversely, you can set the permissions for each file you create then get the download URL's for them individually using getDownloadUrl().

Creating a Google Apps Script which Automatically Executes on Upload

I have an interesting fairly simple problem I am trying to solve but I am at a loss on the proper code to get this to working correctly.
Basically, I have an very old local application running which allow me to print a receipt of a transaction. I have the ability to enable this receipt to be printed to a specific file within a specific directory on my computer or I can set it up to print out automatically to a printer on my computer. Currently I print the data out to a file, then copy the contents of that file and paste it into a word document template and then manually go through and format the data so it looks clean (I should note that the data prints out in fixed field format requiring a specific font and size so its pasts correctly. After all this is done I then email the word or pdf document out.
Essentially what I am trying to do here is automate this method and I thought this should be possible using a Google Apps Script.
My thought here was that it should be possible to:
save all the original files from my application to a specific
directory on my computer
sync that folder with google drive
have a google apps script automatically execute upon upload
have the google apps script automatically use a specific document
template I create with a header/footer and then paste all the
contents from the new file which was uploaded
have the google apps script pattern match certain elements within the contents of
the document and properly format it.
save the document to a specific location with a specific file naming convention
automatically email the document as a doc or pdf based upon a
specific regex matched field within the source document.
Could anyone provide a specific code example which demonstrates how Google apps scripts can be utilized to monitor the contents of a specific Google drive folder to trigger an event immediately after a new file is uploaded?
Thanks in advance!