kspearrin
kspearrin

Reputation: 10788

Failed to construct 'Blob': Array length exceeds supported limit

I try to construct a simple 10.5mb Blob using the following (Chrome browser):

var arr = new Uint8Array(10485833);
var blob = new Blob(arr, { type: 'application/octet-stream' });

I get the error:

Uncaught RangeError: Failed to construct 'Blob': Array length exceeds supported limit.

What is the limit? Why can't I create a 10mb blob? What if I wanted to create a 50mb blob? 1gb blob?

Is Blob the wrong data type to be using here? In the end I am trying to construct some FormData to post to a server. Example:

var fd = new FormData();
var blob = new Blob(arr, { type: 'application/octet-stream' });
fd.append('data', blob, 'filename.zip');

Upvotes: 2

Views: 1669

Answers (1)

Kaiido
Kaiido

Reputation: 137171

This is because Blob expects an array of chunks. The array you are passing is way too big for it. (Probably related)

The solution is simply to wrap this array in a single lenghted array.

var arr = new Uint8Array(10485833);
console.log(new Blob([ arr ], {type:'application/octet-stream'}))
//                   ^_____^_____ wrapped in a single lengthed Array

Upvotes: 7

Related Questions