Reputation: 619
I have a blog built using Jekyll and hosted on Github. In my blog posts, some times I need to share some downloadable files stored on google drive.
At present, I want to know, is there a way to allow file download from google drive only after filling and submitting a google form.
Thank you
Upvotes: 2
Views: 5835
Reputation: 19339
With Apps Script, you can create a function that will run when the form is submitted, and will do the following actions:
In order to make this function run when the form is submitted, you have to install an onFormSubmit
trigger. To do that, while on the script bound to your Form, create the function (let's call it shareLinkOnFormSubmit
) and install the trigger, either manually or programmatically (by copying and running this function — you should change the form id and the function name).
shareLinkOnFormSubmit
could be something similar to the sample below — check inline comments:function shareLinkOnFormSubmit(e) {
var formResponse = e.response;
var email = formResponse.getRespondentEmail(); // Get form respondent email address
var fileId = "your-file-id"; // Get file id (change accordingly)
var file = DriveApp.getFileById(fileId);
file.addEditor(email); // Share the file with the respondent (edit access).
var downloadUrl = file.getDownloadUrl(); // Get download URL (only works for non G-Suite documents)
MailApp.sendEmail(email, "Your file link", downloadUrl); // Send email with download URL
}
https://www.googleapis.com/drive/v3/files/{your-file-id}/export&mimeType={your-mime-type}
Upvotes: 2
Reputation: 3152
Yes, there are a number of way of doing it. The most straightforward way is to share the file as anyone with the link can view.
Add the file id to the following direct download link:: https://drive.google.com/uc?export=download&id=YOUR FILE ID
You can then create a bit ly link to make it a little more presentable
In the presentation settings of the form, you can then add a message and the download link.
There are obvious drawbacks to this such as the ability of the person submitting the form to share the link to other people.
If you wanted to prevent this from happening you can write a script to add read only permissions for the person submitting the form to be able to download the file.
Upvotes: 1