// APIFunction.js
const endpoint = 'https://suraksha.cognitiveservices.azure.com/vision/v3.0/analyze?visualFeatures=Description&details=Landmarks&language=en';
// Function to fetch and analyze image
function fetchAndAnalyzeImage(url) {
const endpoint = 'https://suraksha.cognitiveservices.azure.com/vision/v3.0/analyze?visualFeatures=Description&details=Landmarks&language=en';
fetch(url)
.then(response => response.blob())
.then(imageBlob => {
const formData = new FormData();
formData.append('file', imageBlob);
fetch(endpoint, {
method: 'POST',
headers: {
'Ocp-Apim-Subscription-Key': apiKey
},
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
// Update the UI with the API response data
updateUI(data,url);
console.log(data);
})
.catch(error => {
console.error('Error:', error);
});
})
.catch(error => {
console.error('Image fetch error:', error);
});
}