2
var data = Utilities.newBlob("THis is blob data", MimeType.PLAIN_TEXT, 'test.txt');

if (  ?? ) then Logger.log('yes, this is blob') ;

How to detect data is blob? (not object)

instanceof Blob
// or
instanceof BlobSource

Result: ReferenceError: Blob or BlobSource is not defined

instanceof GoogleAppsScript.Base.Blob;
// ReferenceError: `GoogleAppsScript` is not defined

typeof data
// result: object

Object.prototype.toString.call(data);
// result: [object Object]

1 Answers1

5

Try using duck typing:

if (typeof data.copyBlob === 'function')
{
  // it's probably a blob
  console.log('yep');
}

Reference: Class Blob

Kos
  • 4,890
  • 9
  • 38
  • 42
  • Looks like the best solution indeed ;) I would just wrap it in a function like this: `const isBlob = obj => 'function' === obj.copyBlob` – Dmitry Kostyuk Aug 05 '21 at 12:54