1

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 } 
2
  • Did my answer show you the result what you want? Would you please tell me about it? That is also useful for me to study. If this works, other people who have the same issue with you can also base your question as a question which can be solved. If you have issues for my answer yet, I apologize. At that time, can I ask you about your current situation? I would like to study to solve your issues. Commented Mar 30, 2019 at 23:49
  • Thank you for your response. Commented Apr 21, 2019 at 23:22

1 Answer 1

1
  • You want to save the downloaded file in the specific folder which has the name of game_thumb.
  • You want to set the value of cell "A1" to the filename of downloaded file.

If my understanding is correct, how about this modification?

For your question 1:

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.

From:

var folder = DocsList.getFolder('game_thumb'); 

To:

var folder = DriveApp.getFoldersByName('game_thumb').next(); 
  • In this modification, it supposes that the folder which has the name of game_thumb is only one in your Drive. If there are the folders with several same names, please tell me.

For your question 2:

Please modify as follows.

From:

var result = folder.createFile(fileBlob); 

To:

var name = SpreadsheetApp.getActiveSheet().getRange("A1").getValue(); var result = folder.createFile(fileBlob).setName(name); 
  • From your question, I'm not sure whether you are using the container-bound script or standalone script, and also I'm not sure where sheet there is the cell "A1" is. So this modification supposes that the cell "A1" of the active sheet is used.

References:

If I misunderstood your question and this modification didn't work, I apologize. At that time, can you provide the information of the situation?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.