3

i'm fiddling around with WebRTC file sharing, but now encountered a problem with blob. It seems that (atleast on google chrome) there is a limit of 500mb for blob file.
My Reciever recieves ArrayBuffers and makes blobs out of them, which is stored then in array. When the last ArrayBuffer is recieved - one big blob is constructed, link is made and given to user to download a file. I was trying to send 800mb file but big blob is caped at 500mb and therefore file is corrupted. As i understand it's a well known blob memory limit, and it is somehow can be bypassed (i suppose https://www.sharefest.me/ did it?), but how?
Or maybe there is some another way for the user to get a link to combined arraybuffers and save them as a file?

Here's my reciever's code:

var finalBlob;   
var ind = 0;   
var f = files_r[ind];//file
var part = f.currentChunk;    
var blobs = f.fileblobs;

blobs.push(new Blob([data], {
    type: f.mime
}));
f.currentChunk++; 

if (f.currentChunk === f.totalchunks) {
    finalBlob = new Blob(blobs, {
        type: f.mime
    });
    var link = g(ind + '_link');       
    var url = URL.createObjectURL(finalBlob);
    link.href = url;       
    link.download = f.name;
    console.log("finished");        
}
Max Yari
  • 3,617
  • 5
  • 32
  • 56

1 Answers1

1

You should save your blobs to IndexedDB, then query them, create resulting blob and give link to it. Take a look at discussion here https://code.google.com/p/chromium/issues/detail?id=375297. I used Dexie (wrapper for IndexedDB) for saving/retrieving chunks to IndexedDB.

8alery
  • 11
  • 1
  • So, how will you avoid holding resulting blob in memory, as i understand to create a link you NEED to have this blob at this time in one piece in memory, so 500mb limit is back? – Max Yari Jan 20 '16 at 14:28
  • 1
    Actually not. I don't know why but then your create blob from blobs array browser either doesn't copy blobs data to one chunk and only creates references or make resulting blob file-based like its chunks. You should just try it to see for yourself. – 8alery Jan 27 '16 at 08:20
  • hm interesting, yeal i'll definetely try it some time later, thanks for suggestion! – Max Yari Jan 27 '16 at 15:41
  • Yeah, it works because browsers use the fact that blobs are immutable to stitch together stuff from all kinds of places without any copying involved, since they know that the blobs can't be changed under their feet. :) – Shien Sep 23 '16 at 16:17