Created
February 17, 2015 15:39
-
-
Save tsertkov/b29b9adfd6b9a50a2e44 to your computer and use it in GitHub Desktop.
Google Apps Script save fileBlob splitting it by chunks of given size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Save file splitting it by chunks of 9M | |
* @param {Blob} FileBlob blob data to save | |
* @param {Folder} folder destination folder | |
* @param {Number} chunkSize | |
* @return {String} | |
*/ | |
function saveFileByChunks(fileBlob, folder, chunkSize) { | |
var | |
fileName = new Date().getTime(), | |
fileBytes = fileBlob.getBytes(), | |
fileSize = fileBytes.length, | |
chunksCount = Math.ceil(fileSize / chunkSize), | |
chunkBlob, chunkBytes, file, | |
i = 0; | |
if (!fileSize) { | |
// should not get here in first place :-) | |
return ''; | |
} | |
if (chunksCount) { | |
do { | |
i++; | |
chunkBlob = fileBlob | |
.setBytes(fileBytes.splice(0, chunkSize)) | |
.setName(fileName + '-chunk-' + i + 'of' + chunksCount); | |
file = folder.createFile(chunkBlob); | |
} while (fileBytes.length); | |
} else { | |
fileBlob.setName(fileName); | |
file = folder.createFile(fileBlob); | |
} | |
return fileName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The issue is that when the file is big than 100M, blob methods don't work but throw an error:Zip file content item exceeds limit of 100MB.
But I cannot see official doc mentioning this limit.