Google表单中的FILE_UPLOAD项目类型 [英] FILE_UPLOAD item type in google forms

查看:47
本文介绍了Google表单中的FILE_UPLOAD项目类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google最近在其表单中添加了文件上传功能.

Google recently added a file upload feature to their forms.

但是,我无法在Google脚本中找到有关如何使用它的任何文档.如果我在Google上查看商品类型API,则未列出

However, I am unable to find any documentation on how to use this in google scripts. If I look at the item types API on google, it isn't listed

https://developers.google.com/apps-script /reference/forms/item-type

但是,如果我检查表单中的类型,则会得到"FILE_UPLOAD"类型 responseItem.getItem().getType() //returns FILE_UPLOAD

However, if I check the types in my form, I get a type of "FILE_UPLOAD" responseItem.getItem().getType() //returns FILE_UPLOAD

如果我查看对象,它是一个带有字符串的数组.

If I look at the object, it is an array with a string.

我只是想弄清楚如何获取文件名并重命名.

I am just trying to figure out how to get the filename and rename it.

推荐答案

因此,在考虑了这一点之后,我意识到FILE_UPLOAD类型返回的字符串可能是Google驱动器的文件ID.原来是正确的.因此,您可以使用DriveApp类获取文件并重命名.

So after thinking about this a bit I realized that the string that is returned by the FILE_UPLOAD type is probably the google drive File id. Turns out that is correct. So you can use the DriveApp class to get the file and rename it.

这是我的做法:

for (var f = 0; f < responseItems.length; f++) {
  if (responseItems[f].getItem().getType() === "FILE_UPLOAD") {
    files = responseItems[f].getResponse();
    if (files.length > 0) {
      for (var n in files) {
        var dFile = DriveApp.getFileById(files[n]);
        dFile.setName("new name_" + n);
      }
    }
  }
}

运行此命令时,系统将要求您授予脚本访问驱动器中文件的权限.

When you run this you will be asked to give permission to the script to access files in drive.

希望这可以帮助其他尝试解决此问题的人.

Hope this helps someone else trying to figure this out.

这篇关于Google表单中的FILE_UPLOAD项目类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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