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

GAS中insertImage方法插入图片失败问题求助

Google Apps Script insertImage 突发插入失败问题

我有一个每月定时运行的GAS脚本,负责数据汇总和绘图,此前一直稳定运行,今日突然抛出插入图片失败的错误:

Exception: Failed to insert image. Please make sure the image is valid and try again.

经排查,问题出在insertImage方法上。我没有修改过原文件、代码及任何设置,甚至用极简测试代码复现,结果依然报错,因此推测更可能是Google服务端的规格变更或临时故障,而非代码本身的问题。

调试代码及报错信息

我编写了如下调试代码定位问题:

function insertImageDebugTest(){
 const ss = SpreadsheetApp.getActiveSpreadsheet();
 const summarySheet = ss.getSheetByName('forDebug');

 const fileId = "1qOFsxyR2GBjuryL889GiLQq165xAjNvj"; // 指定Google Drive文件ID
 const file = DriveApp.getFileById(fileId);
 const blob = file.getBlob();
 Logger.log("MIME Type: " + blob.getContentType());

 summarySheet.insertImage(blob, 1, 1).setWidth(323).setHeight(140);
}

运行后得到的报错信息:

Exception: The image could not be inserted. Please verify it is valid and try again.

已确认的信息

  • 目标图片文件大小约1kb,体积无异常
  • 日志输出显示文件MIME类型为image/png,格式合法
  • 插入目标工作表未设置任何保护权限

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 05:22:08