Skip to content

Instantly share code, notes, and snippets.

@arunjayakumar01
Last active December 26, 2021 10:43
Show Gist options
  • Save arunjayakumar01/91eacad08d4809bc8f4ea0ac68667eb9 to your computer and use it in GitHub Desktop.
Save arunjayakumar01/91eacad08d4809bc8f4ea0ac68667eb9 to your computer and use it in GitHub Desktop.
Spit file into blobs
const file = document.getElementById('upload').files[0];
const CHUNK_SIZE = 10000000; // 10MB
const fileSize = file.size;
const CHUNKS_COUNT = Math.floor(fileSize / CHUNK_SIZE) + 1;
let start, end, blob;
for (let index = 1; index < CHUNKS_COUNT + 1; index++)
{
start = (index - 1) * CHUNK_SIZE;
end = (index) * CHUNK_SIZE;
blob = (index < CHUNKS_COUNT) ? file.slice(start, end) : file.slice(start);
// get blob and send the data to the upload functions
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment