Utilities.ungzip() GmailAttachment object

640 views
Skip to first unread message

Harry Hoffman

unread,
Jun 14, 2022, 8:07:33 AM6/14/22
to Google Apps Script Community
Hi Folks,

Wondering if anyone has successfully used Utilities.ungzip to take a Gmail Attachment and decompress it. I have the following code which is bombing on on trying to use Utilities.ungzip(). The error message, Error
Exception: Invalid argument,  is not helpful :-(

The console output shows a file with a byte count and mime type of gzip (see below code). I have no idea what I'm doing wrong. Can anyone point me in the right direction?


for (var f of files)
{
var file_name = f.getName();
console.log("Attachment found for: " + file_name);
if ( file_name.match(/\.gz/) )
{
var blob = f.copyBlob();
console.log(files);
console.log(f);
console.log(blob.getSize(), blob.getContentType(), typeof blob);
var uncompressedBlob = Utilities.ungzip(blob.copyBlob());
console.log(typeof uncompressdBlob);
}
}

8:01:17 AM
Info
Attachment found for: Host - Applicable Errata-2022-06-05.csv.gz
8:01:17 AM
Info
[ { toString: [Function], getSize: [Function], getHash: [Function], getName: [Function], getBytes: [Function], setName: [Function], getContentType: [Function], setContentType: [Function], setContentTypeFromExtension: [Function], getDataAsString: [Function], setDataFromString: [Function], isGoogleType: [Function], getAllBlobs: [Function], copyBlob: [Function], setBytes: [Function], getAs: [Function] } ]
8:01:17 AM
Info
{ toString: [Function], getSize: [Function], getHash: [Function], getName: [Function], getBytes: [Function], setName: [Function], getContentType: [Function], setContentType: [Function], setContentTypeFromExtension: [Function], getDataAsString: [Function], setDataFromString: [Function], isGoogleType: [Function], getAllBlobs: [Function], copyBlob: [Function], setBytes: [Function], getAs: [Function] }
8:01:17 AM
Info
1980026 'application/gzip' 'object'

Clark Lind

unread,
Jun 14, 2022, 10:22:34 AM6/14/22
to Google Apps Script Community
Since you have already made a copy of the blob (gzip file), I think it doesn't like creating a second copy. Try just   var uncompressedBlob = Utilities.ungzip(blob);

Harry Hoffman

unread,
Jun 14, 2022, 12:49:55 PM6/14/22
to Google Apps Script Community
Thanks, I had originally tried that but it doesn't work either. The docs say it takes a function as an argument but I'm wondering if I'm passing the wrong thing into it.
Reply all
Reply to author
Forward
0 new messages