1

I've been trying create a file and then access its ThumbnailLink in GAS.

this works well -

let _file = DriveApp.createFile("TEMPFILE.svg", svg);
let file = Drive.Files.get(_file.getId());

(is this the best practice?)

now, when I'm trying to get the thumbnailLink - it's sometimes null (as in sometimes there is actually a value there and sometimes not). With other files I have (that I did not just create) - I get it in the same way without any problems. In debug - no problem at all and I can always see the value.

My guess is that the link is not ready yet.

Any way to wait for it? or to do something differently so that it's there when I need it?

2 Answers 2

1

In the previous answer originally was suggested to use Utilities.sleep(milliseconds) and later it was edited to use a while loop with a simple expression. Those solutions have several caveats, specially due to the use of 100 as parameter because sometimes the thumbnail generation could take longer and because it's prone to trigger message errors due to the Google Apps Script and the Drive API quotas.

To prevent the above implement the exponential backoff algorithm. One way to do this is by using GASRetry a gist shared by Peter Hermann on 2012. It's worthy to note that there are other clever people that have shared their own implementation of this algorithm.

Related

0

Adding this piece of code did the trick -

let _file = Drive.Files.get(file.getId());

while (_file.thumbnailLink == null) {
    Logger.log("waiting");
    Utilities.sleep(100);
    _file = Drive.Files.get(file.getId());
}

and I see that it's "waiting" once and then it's ok and thumbnailLink has a value.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.