I want to delete the file of the respondents uploaded by the Google form upload function after submitting the form.

Asked 2 years ago, Updated 2 years ago, 87 views

I am currently thinking of using the upload function in Google form.

First of all, regarding the specifications of the Google form,

at the time the respondent uploaded the file before submission The respondent's owner's file will be saved to the respondent's drive (just below).

Submitting the form afterwards

in the file storage location on the drive on the form creator side The form creator saves the owner's upload file.

So, at this rate,
Respondents consciously submit the form
You have to erase the uploaded file directly under your drive
Upload files will continue to accumulate directly below the drive.
Using GAS or other means (if any) somehow
We would like to delete the respondent's upload file after submitting the form.

Currently, referring to the Internet and books, the form GAS is as follows:
I am writing a program to get answers and send emails.

function noticeFileUpload(e){
    varitemResponses=e.response.getItemResponses();

    for (vari=0;i<itemResponses.length;i++) { 
        variableResponse=itemResponses[i]; 
        varquestion=itemResponse.getItem().getTitle(); 
        var answer = itemResponse.getResponse();

        Logger.log(question);
        Logger.log(answer);

        if(question=="submission document"){
            varfileId=answer;
            varfile=DriveApp.getFileById(fileId);

            var address = 'email address'; 
            US>vartitle='[Google Form Send Test] File Uploaded'; 
            var content=' file uploaded successfully.\n\n'
            + US>'File Name:'+file.getName()
            + US>'\n\n'
            + *This is an automated email sent from Google form.'; 

            GmailApp.sendEmail(address, title, content);
        }
    }
}

In this way, I know the code to get the answer, but
I don't know the specific code to retrieve the files that the respondents uploaded to their drive.

Delete the automatically appended account name from the file name saved in the answer. Do I have to search for a file with the same name directly under the drive → delete them?
(In that case, I am also concerned about how to deal with files with the same name if they already exist.)

I'm sorry, but I'd appreciate it if you could tell me.
Thank you for your cooperation.

google-apps-script

2022-09-30 21:39

1 Answers

In conclusion, it is possible.

Read the following documentation to help you:

Forms Service|Apps Script|Google Developers
Drive Service|Apps Script|Google Developers

As for how to write Google Apps Script itself, you have to study it yourself, but based on ES5, there is a lot of information on the Internet and books, and it is a relatively easy language for beginners to learn, so please do your best.
Overview of Google Apps Script | Apps Script | Google Developers
[Save] Complete Google Apps Script Manual for Beginners

Additional note 2019-03-05_15-29-37

Google Form's Web Client feature allows you to write your answers to a spreadsheet (new answers will also be automatically added and edited).

Also, the Google Drive side URL of the file uploaded by the respondent is included in the spreadsheet, so get the ID of the file from this URL, use DriveApp.getFileById to get File and then File.getParent=You can actually delete the file by running Folder.removeFile by obtaining https://developers.google.com/apps-script/reference/drive/folder"rel="nofollow noreferrer">Folder.


2022-09-30 21:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.