mercredi 5 février 2020

How to upload a image iniside of project, to firebase storage? Web

I need to upload a default profile image to firebase storage. However it turns out that i cannot add a default input value. I have tried passing the src of the image to the method to upload but I get errors, mainly the issue being that the data types are not the same.

Here is my code:

$('.js-form').on('submit', event => {

  var everythingChecksOut = true;

  event.preventDefault();

  document.getElementById("signUpBtn").style.background='#C0C3FA';
  document.getElementById("signUpBtn").innerHTML='...';
  document.getElementById("signUpBtn").disabled = true;

  const email = $('#emailInput').val() || state.email;
  const password = $('#psw').val() || state.password;
  const username = $('#uname').val();

  console.log(email, password, username);

  var fileButton = document.getElementById('fileButton');
  var file = fileButton.files[0];

  if (file == undefined) {

    everythingChecksOut = false;

  }

  if (everythingChecksOut) {
    firebase.auth().createUserWithEmailAndPassword(email, password)
    .then(function(user) {

      firebase.auth().onAuthStateChanged(function(user) {
        console.log("if user????");

        if (user) {
          console.log("yes");

          // Create a root reference
          var storageRef = firebase.storage().ref();
          console.log("...");

          var fileButton = document.getElementById('fileButton');

          var file = fileButton.files[0];

          var storageRef = firebase.storage().ref(user.uid+'/'+file.name);
          var task = storageRef.put(file)
         ...

The file is located at: "images/default.png"

How can I upload this local file if, like my condition states, !((file == undefined))




Aucun commentaire:

Enregistrer un commentaire