2016-02-25 70 views
0

当我尝试使用Google Apps脚本从URL下载图片时,出现以下错误。DriveApp.createFile导致服务器错误

We're sorry, a server error occurred. Please wait a bit and try again. 

这是代码。

function TT() { 
    var response = UrlFetchApp.fetch('https://www.dropbox.com/s/g9jtm390l67uqkb/128.png?dl=1'); 
    var blob = response.getBlob(); 
    Logger.log(blob.getContentType()); 
    var file = DriveApp.createFile(response); 
} 

回答

0

那么,应该尝试从它的blob创建一个文件,而不是从它自己的响应。

function TT() { 
    var response = UrlFetchApp.fetch('https://www.dropbox.com/s/g9jtm390l67uqkb/128.png?dl=1'); 
    var blob = response.getBlob(); 

    Logger.log(blob.getContentType()); 

    var file = DriveApp.createFile(blob); 
} 

我运行了一个测试,它的工作完美。

+1

这很奇怪,它给出了一个错误,并使文件。 – DavidVdd

+0

确实,我今天试过了,我也得到了那个服务器错误,我想这不是关于代码的东西......你可以做的是把“var file = DriveApp.createFile(blob);”在现在的“尝试捕捉”声明中。 – LeandroP