0

in a Google Script I have to download files larger than 50MB. Server that serve files support range command, so I can download chunks of files but I have problems during the merge process.

Following an example of the code I tried to use and the problem I faced (RangeError: Invalid array length)

let pieceSize = 52428800;
let steps = Math.ceil(fileSize / pieceSize);
let blobs = [];
let datas = null;
for (let i = 0; i < steps; i++){
   let b = "bytes=" +(i*pieceSize)+ "-"+Math.min((i+1)*pieceSize-1, fileSize);
   let params = {method: "get",    headers: {  Range: b, }, };
   Logger.log("Gettinng piece "+i+" : "+b);
   blobs.push(UrlFetchApp.fetch(url, params).getBlob());
   if (datas == null){
     datas = blobs[i].getBytes();
   } else {
     datas = datas.concat(blobs[i].getBytes()); // RangeError: Invalid array length
   }
}
let blob = Utilities.newBlob(datas);
let file = DriveApp.createFile(blob)

I looked for other solutions to merge downlaoded data (maybe as files, or as blobs?) but I can't find functions to reach my goal without moving to Byte[].

Thanks

brazoayeye
  • 199
  • 1
  • 1
  • 13

0 Answers0