google-apps-script - 通过 URL 插入图像在 Google Apps 脚本中不起作用
问题描述
我创建的 Google 表单中的一个响应是上传一张图片,该图片与链接电子表格中的 URL 一起保存在我的 Google Drive 中。在 Google 幻灯片中,我创建了一个 Apps 脚本,并成功地为每一行/条目以及该行中的文本、电子表格创建了幻灯片,但在尝试使用 URL 插入图像时遇到了困难。在运行时,我抛出异常“无法检索 URL 处的图像......请确保图像有效且可公开访问。” 当我手动尝试通过菜单栏通过 URL 插入图像时,我也会遇到同样的错误。我驱动器中的所有文件夹和文件都不受限制,因此互联网上的任何人都可以通过此链接查看图像。我已经在我的浏览器和其他浏览器中进行了测试,它成功打开了图像,但在幻灯片中没有。
这是我从函数中使用的一些代码,但不包括对电子表格的引用。也尝试在 URL 末尾添加“/edit”、“/view”,但结果相同。记录器确实显示正在从工作表中获取 URL。
function CreateSlides() {
var deck = SlidesApp.getActivePresentation();
var a = 2; // data begins in second row in spreadsheet
while (sheet.getRange(a,2,1,1).getValue() != "") {
//Insert new slide if not first slide
if (a != 2) {
slide = deck.insertSlide(a-2,SlidesApp.PredefinedLayout.BLANK); //add new slide
} else {
slide = deck.getSlides()[0]; //get first slide
}
// Insert image of painting
Logger.log(sheet.getRange(paintingURLCol + a).getValue());
var picture = slide.insertImage(sheet.getRange(paintingURLCol + a).getValue() + '/view');
// Edit picture size and position
// Increment counter to next row in sheet
a++;
}
}
解决方案
Google 表单按上传问题类型记录的 URL 不能与诸如此类的方法一起使用,insertImage(URL)
因为这些 URL 不受支持。相反,您应该使用:
https://drive.google.com/uc?id=DRIVE_FILE_ID
上述情况是因为记录到电子表格的 URL 指向嵌入图像的页面,而不是实际的图像文件。
有关的
推荐阅读
- django - Django - 使用自定义用户模型进行身份验证返回无
- java - 画圈的动画
- mysql - MYSQL-how to insert geometry data
- c++ - c++ type alias not working when testing specialization
- php - 在php中将整个网站重定向到新网站的主页
- python - Merge different length dataframes, Join column in dataframe dont have unique values
- node.js - 进程崩溃:TypeError:回调不是函数
- django - 没有搜索结果 Django 2.1 Solr 6.5
- mysql - Laravel 的原始查询在哪里?
- dart - 如何正确查看 Flutter 中的所有对象数据?