Sending file attachments along with Google Forms submission, having them emailed?
Asked Answered
D

1

9

I'm building a form using Google Forms, and then taking the form out into my web page so I can directly edit the form (so I do have complete control over the form code).

Right now I'm able to submit the results send to Google Docs (published on 2012), and then have the results emailed me to me (published on 2012).

I want to add a file attachment to these submissions, using:

<input type="file" name="datafile" id="filedata" size="40">

I know I can use mailApp.sendEmail's advanced arguments, specifically the attachments argument, or the inlineImages argument.

But how do I access the file values in order to attach them to send?

Declinatory answered 15/2, 2013 at 21:13 Comment(7)
Is the user submitting a file through your Google Form? I do not believe this is possible with Google Forms.Pinetum
This is something I'd like to be able to do, even if that file isn't stored in Google. If you look at the first link in my post, you can extricate the form out of the "official" GDocs form, then manipulate the form html however you'd like, even by adding form fields.Declinatory
have your modified code store the file as a URL. The user would need to have the attachment already somewhere on a public url. Then just use urlFetchApp to get it as a blob and attach to email. If you want something more complex like allowing the user to chose a file from their device, its way harder as you need code and authentication to save the attachments somewhere you can get them later.Parsimony
The code on the second linked article use DocList (google-docs-api), a Google Apps Script that is now deprecated.Covell
Possible duplicate of Google Forms: Sending with Attachments (getFileById)Covell
I'm not able to follow. When/where/how is the user uploading the file? Are you using Google Forms or are you building your own form somewhere?Meyerhof
If you're using a Google Form, then the form will tell you the file IDs of the uploaded files. You can use that to attach them to an email.Meyerhof
C
0

As of July 6th, 2024, this question looks obsolete. Nowadays, Google Forms has File Upload among the built-in question types.

It's worth noting that this question type can't be added using Google Apps Script. It should be added using the Google Forms editor.

Regarding

I want to add a file attachment to these submissions, using:

As of today, this is not possible. Instead, use the question type File Upload.

You should grab the form submission data to access the File Upload. This could be done using a form submit trigger from the script in the form or a script in a spreadsheet.

The File Upload response contains the id of the uploaded file. To grab the file and send it as an email attachment, use DriveApp.getFileById(file_upload_response).

Resources

Related

Covell answered 7/7 at 3:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.