Hi @Alex Kondr
It seems like you are trying to send a base64-encoded image in the dataUrl
variable as the body of the POST request. However, the headers you are using (Content-Type: multipart/form-data
) are not appropriate for sending base64-encoded data. Instead, you should send the image as a binary payload with the correct Content-Type
header for image data.
follow these kindly
- Decode the base64 image data into binary format.
- Set the correct
Content-Type
header for image data in the request. - Make the POST request with the binary image data.
// Assuming dataUrl contains the base64 image data (data:image/png;base64,blahblahblah) // Step 1: Decode the base64 image data into binary format const base64Image = dataUrl.split(',')[1]; const binaryImage = atob(base64Image); const byteArray = new Uint8Array(binaryImage.length); for (let i = 0; i < binaryImage.length; i++) { byteArray[i] = binaryImage.charCodeAt(i); } // Step 2: Set the correct Content-Type header for image data in the request const requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/octet-stream', // Set the correct Content-Type for image data 'Ocp-Apim-Subscription-Key': 'my api key here', }, body: byteArray, // Use the binary image data as the request body }; // Step 3: Make the POST request with the binary image data fetch('myEndpointHere/vision/v3.1/describe?overload=stream&maxCandidates=1', requestOptions) .then(async (response) => { const isJson = response.headers.get('content-type')?.includes('application/json'); const data = isJson && (await response.json()); // check for error response if (!response.ok) { // get error message from body or default to response status const error = (data && data.message) || response.status; return Promise.reject(error); } else { console.log(data); } }) .catch((error) => { console.error('There was an error!', error); });
kindly accept if this helps thanks