Failed to construct ‘blob’: the object must have a callable @@iterator property.

The error “failed to construct ‘blob’: the object must have a callable @@iterator property” occurs when trying to create a new Blob object in JavaScript, but the object passed as an argument does not have a callable @@iterator property.

The @@iterator is a well-known symbol in JavaScript that indicates an object is iterable and can be looped over using a for…of loop or other iterable methods like Array.from(). When constructing a new Blob object, the data passed as an argument should be iterable, such as an array, a string, or a typed array.

Here are some examples of how to properly construct a Blob object:

Example 1: Creating a Blob from an array

    
const data = ['Hello', 'World'];
const blob = new Blob(data, { type: 'text/plain' });
console.log(blob);
    
  

In this example, an array containing two strings is passed as the data argument. The second argument is an optional options object specifying the MIME type of the Blob. The resulting Blob object will contain the two strings concatenated together.

Example 2: Creating a Blob from a string

    
const data = 'Hello World';
const blob = new Blob([data], { type: 'text/plain' });
console.log(blob);
    
  

In this example, a single string is passed as the data argument. The resulting Blob object will contain the string as is.

Example 3: Creating a Blob from a typed array

    
const buffer = new Uint8Array([72, 101, 108, 108, 111]);
const blob = new Blob([buffer], { type: 'application/octet-stream' });
console.log(blob);
    
  

This example demonstrates creating a Blob object from a typed array. The resulting Blob object will contain the binary data.

Make sure to check the data being passed to the Blob constructor and ensure it is iterable. If the error still persists, double-check for any other potential issues in your code.

Read more

Leave a comment