2

I have he base64 string of an image and I'm trying to convert it into an 'application/octet-stream' because that's what the api requires. I think I've done that by creating a blob as you can see from my function. When I make the api call I keep getting the message in the title. Anyone know what's wrong?

I think it might be that my blob is not an octet-stream but I've tried both sending the normal base64 string and the blob. Please help, really desperate here

const blobPdfFromBase64String = base64String => {
        const byteArray = base64.toByteArray(base64String);
       return new Blob([byteArray], { type: 'application/octet-stream' });
    };

    let img = route.params.image;


    const sendImage = async() => {
        let url = `${config.ENDPOINT}vision/v3.0/read/analyze`;
        let headers = new Headers();
        let blob = blobPdfFromBase64String(img.base64);
        headers.append('Content-Type', 'application/octet-stream');
        headers.append('Ocp-Apim-Subscription-Key', config.KEY);
        try {
            let response = await fetch(url, { method:'POST', headers, body:blob});
            let json = await response.json();
            console.log(json)
            return json;
        } catch (error) {
            console.log(`Error in sendImage, ${error}`);
        }
    }
Oyebola
  • 141
  • 4

0 Answers0