gpt4 book ai didi

javascript - Google Apps 脚本如何检测 blob 类型?

转载 作者:行者123 更新时间:2023-12-02 02:04:13 25 4
gpt4 key购买 nike

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

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

如何检测数据是blob?(不是对象)

instanceof Blob
// or
instanceof BlobSource

结果:ReferenceError:BlobBlobSource 未定义

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

typeof data
// result: object

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

最佳答案

尝试使用duck typing :

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

引用:Class Blob

关于javascript - Google Apps 脚本如何检测 blob 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68665661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com