Google表单将“文件上传"重命名为提交给“问题-提交者" [英] Google Forms Rename "File upload" File to "Question - Submitter"

查看:91
本文介绍了Google表单将“文件上传"重命名为提交给“问题-提交者"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Forms收集团队成员的图像,并且我想确保上传到Google Forms并保存在Google Drive中的每个文件都具有相同的命名约定.

I am using Google Forms to collect images from team members and I want to ensure that each file that is uploaded to Google Forms and saved in Google Drive has the same naming convention.

团队成员需要将五个 文件上传 问题上传到他们的图像.文件将以随机文件名后跟- firstName lastName的形式放置在Google云端硬盘文件夹中.在 onFormSubmit 触发器上,我想将用户提供的文件的名称更改为fileUploadQuestionName - firstName lastName.

There are five File upload questions that team members are asked to upload their images to. The files are placed into Google Drive folders with random file names followed by - firstName lastName. On an onFormSubmit trigger I would like to change the names of the user-provided files to fileUploadQuestionName - firstName lastName.

我对Google Apps脚本还很陌生,我也不知道如何去做.任何帮助将不胜感激!

I am pretty new to Google Apps Script and I have no idea how to go about doing this. Any help would be greatly appreciated!

推荐答案

您可以通过以下过程更改每个表单提交上载文件的名称

  • 使用form.getResponses()[LAST FORM SUBMISSION]
  • 检索最后一个表单响应 onFormSubmit
  • 使用getItemResponses()[QUESTION NUMBER].getResponse()
  • 检索上传文件的ID
  • 使用DriveApp打开文件ID,并根据需要更改其名称
  • You can change the name of the uploaded file on each form submit by the following process

    • retrieve the last form response onFormSubmit with form.getResponses()[LAST FORM SUBMISSION]
    • retrieve the ID of the uploaded file with getItemResponses()[QUESTION NUMBER].getResponse()
    • open the file ID with DriveApp and change its name as desired
    • function myFunction() {
        var form=FormApp.getActiveForm();
      // returns the total number of form submissions
        var length=form.getResponses().length;
      //replace QUESTION NUMBER through the index of the question prompting the file upload - keep in mind that the first question has the index 0
        var id=form.getResponses()[length-1].getItemResponses()[QUESTION NUMBER].getResponse();
      //getResponses()[length-1] retrieves the last form response, accounting for the fact that the first index is zero and hte last length-1
      //gets the name of the question
        var fileUploadQuestionName=form.getResponses()[length-1].getItemResponses()[QUESTION NUMBER].getItem().getTitle();
      //accesses the uploaded file
        var file=DriveApp.getFileById(id);
        name = file.getName();
      //changes the file name
        var name = fileUploadQuestionName+' - '+name.split(' - ')[1]
        file.setName(name);
      }
      

      PS:如果要更改后验名称,请更改所有已提交文件的名称,而不仅仅是最后一个文件-您需要遍历所有表单响应:

      PS: If you want to change a posteriori the names of all the files submitted and not just the last files - you need to loop through all form responses:

      for(var i=0;i<length;i++){ 
       var id=form.getResponses()[i].getItemResponses()[QUESTION NUMBER].getResponse();
        ...
       ...
        }
      

      这篇关于Google表单将“文件上传"重命名为提交给“问题-提交者"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆