Microsoft Cognitive API keeps telling me : “message”: “The input data is not a valid image or password protected.”

喜你入骨 提交于 2020-07-21 06:38:57

问题


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}`);
        }
    }

来源:https://stackoverflow.com/questions/62046313/microsoft-cognitive-api-keeps-telling-me-message-the-input-data-is-not-a-v

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!