user12046449
user12046449

Reputation:

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?

Upvotes: 3

Views: 7178

Answers (3)

Dhruv Shah
Dhruv Shah

Reputation: 1661

Have you tried

var sizeInBytes = blob.size

Upvotes: 1

TheMaster
TheMaster

Reputation: 50574

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

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

const size = blob.getBytes().length;

Upvotes: 9

ag-dev
ag-dev

Reputation: 243

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

Upvotes: 4

Related Questions