You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Google Apps Script为共享云端硬盘文件加自定义属性报错求助

问题解决:共享云端硬盘文件添加自定义属性报错修复

错误原因

调用Drive.Files.update时参数顺序错误:该方法的第三个参数应为媒体上传数据(mediaData),但你传入了配置选项对象{supportsAllDrives: true},导致系统误将其识别为文件内容上传,触发类型不匹配报错。

修复方案

正确的Drive.Files.update参数顺序是:resource, fileId, mediaData, options。由于仅需更新文件属性、无需上传文件内容,需将mediaData设为null,并把配置选项移至第四个参数位置。

修改后的代码

addCustomProperties(fileID, Customer_name, Process_Type, Priority);

function addCustomProperties(fileID, customerName, processType, Priority) {
  var resource = {
    properties: {
      CustomerName: customerName,
      ProcessType: processType,
      Priority: Priority
    }
  };
  // 修正参数顺序:添加null作为mediaData参数,将选项移至第四个位置
  Drive.Files.update(resource, fileID, null, {supportsAllDrives: true});
}

额外注意事项

  • 确保已在Google Apps Script编辑器中启用Drive API高级服务(编辑器菜单 > 资源 > 高级Google服务 > 找到Drive API并启用)
  • 确认当前脚本拥有共享云端硬盘的编辑权限

内容的提问来源于stack exchange,提问作者Yunlong

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 13:25:55