Trying to set a Blob object into React State hook

Viewed 883

I'm trying to set a blob object into my state using useState but when i try to validate if the state is instance of Blob i'm getting false.

First, my state:

const [frontDocumentIMG, setFrontDocumentIMG] = useState();

Second I have an URL like

"blob:http://localhost:3000/e9310b00-fa35-4cbc-9a0e-788bc61f5953"

and I use fetch to get the blob and then set the blob into my state.

fetch(props.state.frontDocument)
  .then((res) => res.blob()) // Gets the response and returns it as a blob
  .then((blob) => {
    console.log(blob);
    setFrontDocumentIMG(blob); //THIS IS MY FUNCTION TO SET THE STATE
  });

But when I try to add the blob to an FormData I get the error "The second parameter is not a Blob instance".

Is there a way to put the blob into the state and not losing the instance of blob? Or another way to get the Blob from the URL.

0 Answers
Related