I'm trying to fetch a large JSON in Google Script but end up with a truncated response since it hit the 50Mb maximum fetch response size. So I'm now trying to get it compressed since in my browser the request takes only 12Mb but can't find a way to make it work, any idea?
var response = UrlFetchApp.fetch(URL, {
method: "GET",
headers: {
'accept-encoding': 'gzip',
"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36"
}
});
var body = response.getContentText(); // Return the full JSON, should have been compressed
console.log(body.length); // Return 50Mb
console.log(body.substring(body.length-50)); // Can confirm it's truncated and not encoded
var res = Utilities.ungzip(response.getBlob()); // Error Invalid argument
I'm not getting the compressed response and I'm getting Error Invalid argument
on the last line.
I tried some other ways but still can't get a compressed response.