在 Apps 脚本中取消 gzipping Blob 时出现“无效参数”错误

Дми*_*лах 7 google-apps-script

我有一个脚本,可以从第 3 方 API 接收 gzipped blob。我正在尝试使用它来解压缩它Utilities.ungzip(),但收到无效参数错误。这是示例代码:

var liveReportResponse = UrlFetchApp.fetch(url)
var unzipped = Utilities.ungzip(liveReportResponse.getBlob()) // Fails with Invalid Argument error
Run Code Online (Sandbox Code Playgroud)

奇怪的是,我可以使用驱动器文件作为中间存储来提取内容:

var image = liveReportResponse.getBlob()
var file = {
  title: 'some_file_.gzip'
};
file = Drive.Files.insert(file, image);
var file = DriveApp.getFileById(file.id)
var blob = file.getBlob()
var someBytes = Utilities.ungzip(blob) // It works
var data = someBytes.getDataAsString()
Run Code Online (Sandbox Code Playgroud)

希望能帮助解决这个问题。

Дми*_*лах 11

最终,设法解决了这个问题:

liveReportResponse.getBlob().setContentType('application/x-gzip')
Run Code Online (Sandbox Code Playgroud)

application/x-gzip似乎没有在任何地方记录,但我是从blob.getContentType()