2

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');
0

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.