Search code examples
javascriptgoogle-apps-scriptgoogle-sheetsgoogle-drive-apiblob

How to get the size of the Blob object in Google Apps script?


I have created a script where in Google Sheet is converted to PDF and sent in an email (via Gmail API).

Please find the below syntax which is used to convert sheet to PDF

var blob=DriveApp.getFileById(<<Google Sheet ID>>).getAs('application/pdf');

what can be done to find out the size of the blob here?


Solution

  • Blob has getBytes() method, which returns a byte array.

    Size of the blob(in bytes) = byte array's length

    const size = blob.getBytes().length;