I am storing images uploaded on the application on firebase storage. I then need to retrieve the image and send it to Microsoft's Cognitive Service (emotion API). I tried sending the download URL of an image to the API but it doesn't take - it gives me a 400 error. How can I send an image from firebase storage to the Emotion API.
Below, is the code that stores the uploaded file to firebase storage... I need to continue the code at the end of this code snippet.
download_photo_btn.addEventListener("click", function(e) {
var user = firebase.auth().currentUser;
var uid;
if (user != null) {
uid = user.uid; // The user's ID, unique to the Firebase project. Do NOT use
// this value to authenticate with your backend server, if
// you have one. Use User.getToken() instead.
}
var snap = takeSnapshot();
var blob = dataURItoBlob(snap);
// Create a root reference
var storageRef = firebase.storage().ref();
// Initial UID for images
var selfieID = 0;
// Create a reference to 'mountains.jpg'
var selfieRef = storageRef.child(uid + '-' + selfieID++ + '.png');
// Create a reference to 'images/mountains.jpg'
var selfieImagesRef = storageRef.child('/selfies/' + uid + '-' + selfieID++ + '.png');
// While the file names are the same, the references point to different files
selfieRef.name === selfieImagesRef.name // true
selfieRef.fullPath === selfieImagesRef.fullPath // false
// send image file to firebase storage
var file = blob;
var uploadTask = selfieImagesRef.put(file);
});