Reputation: 816
I am using this script to download a URL set in a google sheet cell to a specific folder in google drive called "game_thumb" If cell B1 is "yyyyy.com/picture.png" I expect picture.png to be downloaded to the google drive folder. I get an error"ReferenceError: "DocsList" not defined. (line 5). I also would like the file to be renamed to include Cell A1 (contentCellA1_picture.png) before it is downloaded to drive. The code I use:
function getFile(fileURL) {
// see https://developers.google.com/apps-script/class_urlfetchapp
var response = UrlFetchApp.fetch(fileURL);
var fileBlob = response.getBlob()
var folder = DocsList.getFolder('game_thumb');
var result = folder.createFile(fileBlob);
debugger; // Stop to observe if in debugger
}
Upvotes: 1
Views: 2926
Reputation: 201683
game_thumb
.If my understanding is correct, how about this modification?
From your question, it is found that although I'm not sure whether the data is the file blob you want, the data from the URL can be retrieved. So in order to remove the error, please modify as follows.
var folder = DocsList.getFolder('game_thumb');
var folder = DriveApp.getFoldersByName('game_thumb').next();
game_thumb
is only one in your Drive. If there are the folders with several same names, please tell me.Please modify as follows.
var result = folder.createFile(fileBlob);
var name = SpreadsheetApp.getActiveSheet().getRange("A1").getValue();
var result = folder.createFile(fileBlob).setName(name);
If I misunderstood your question and this modification didn't work, I apologize. At that time, can you provide the information of the situation?
Upvotes: 1