【问题标题】:I can´t upload documents to Google Sites from url using Apps Scripts我无法使用 Apps 脚本从 url 将文档上传到 Google 协作平台
【发布时间】:2020-04-23 23:47:08
【问题描述】:

我正在尝试使用 G-Drive 中的 URL 将文件上传到 Google 协作平台。我正在使用此代码,它正在运行,但是当我刷新站点时,文件不会上传。

function uploadFiles(url, h) {  
    try {
    var url = "myFileUrl";
    var site = SitesApp.getSite("mySite", "myPage");
    var page = site.getAllDescendants()[0];
    var id = getIdFrom(url); // function that I have that gives you the id of an url
    var blob = DriveApp.getFileById(id).getBlob();
    var attachment = page.addHostedAttachment(blob);
    return attachment.getUrl(); 
     }
    catch(error)  
{
    return error.toString();  
}

【问题讨论】:

标签: google-apps-script google-sites


【解决方案1】:

我运行它时没有错误。我已经用下面的代码解决了这个问题,但现在我有了一个新问题。当我上传它作为 .html 文件上传的文件时,我想将它上传为 .pptx 或 . xls 取决于它是什么类型的文档。

function uploadblob() { 
      var url = "myFileUrl;
      var site = SitesApp.getSite("mySite", "myPage");
      var page = site.getAllDescendants()[0];
      var blob = UrlFetchApp.fetch(url).getBlob();
      var attach = page.addHostedAttachment(blob);
}

【讨论】:

  • 如果您有新问题,请随时撰写新帖子。
猜你喜欢
  • 1970-01-01
  • 2013-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-05
相关资源
最近更新 更多