0

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?

Rubén
  • 34,714
  • 9
  • 70
  • 166

3 Answers3

7

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

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

const size = blob.getBytes().length;
TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • Note that getBytes() has a size limit, so this wont work for very large files – nwaltham Aug 18 '20 at 08:20
  • @nwaltham Do you know the limit? I haven't heard any such thing till now. – TheMaster Aug 18 '20 at 10:02
  • @nwaltham Related: https://stackoverflow.com/questions/60181888/google-apps-script-get-range-of-bytes-from-binary-file/60182078?noredirect=1#comment112261635_60182078 – TheMaster Aug 19 '20 at 12:01
3

If we refer to the MDN documentation (https://developer.mozilla.org/en-US/docs/Web/API/Blob/size)

Just do it like this :

var sizeInBytes = blob.size
ag-dev
  • 213
  • 2
  • 12
1

Have you tried

var sizeInBytes = blob.size
Saeed
  • 3,294
  • 5
  • 35
  • 52
Dhruv Shah
  • 1,611
  • 1
  • 8
  • 22