0

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);
  });
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Mike
  • 59
  • 2
  • 7

1 Answers1

0

You have two options:

  • Since you already have it handy, you can upload the same blob to the Emotion API. This does mean that you will upload your image data twice, once to Firebase and once to Microsoft.
  • You can get a public URL for your storage item. This is the relevant documentation. Note that you may need to adjust the permission of your storage for Cognitive Services to access the image.

Some additional info here: firebase storage - getting image URL

Community
  • 1
  • 1
cthrash
  • 2,938
  • 2
  • 11
  • 10