Upload multiple images on Firebase Storage and then create post









up vote
0
down vote

favorite












I have a file input from which I add a series of images to an array called var immaginiPost = . I then want to get all of these images and add them to Firebase Storage and then once these are uploaded get also the title and content of a post from other two text inputs and create a post on Firebase Database where I also uplaod every downloadUrl for each image. I have a problem where I need to wait that all images have been uploaded to Storage and all downlaodUrls have been added to the var immaginiDownloadURL = array before creating the post and I can't figure this out. Thank you in advance.



 //Here create a new post
function newPost()
var postsStorageRef = firebase.storage().ref().child('posts');
var postDatabaseRef = firebase.database().ref().child('posts');
var postKey = firebase.database().ref().child('posts').push().key;
immaginiPost.forEach(function(file)
let uploadTask = postsStorageRef.child(postKey).child(file.name).put(file);

uploadTask.on('state_changed', function(snapshot)
// Observe state change events such as progress, pause, and resume
// Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log('Upload is ' + progress + '% done');
switch (snapshot.state)
case firebase.storage.TaskState.PAUSED: // or 'paused'
console.log('Upload is paused');
break;
case firebase.storage.TaskState.RUNNING: // or 'running'
console.log('Upload is running');
break;

, function(error)
// Handle unsuccessful uploads
console.log('Unsuccessful upload');
, function()
// Handle successful uploads on complete
// For instance, get the download URL: https://firebasestorage.googleapis.com/...
uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL)
console.log('File available at', downloadURL);
immaginiDownloadUrl.push(downloadURL);
//Then create the post...
//TODO: Think of how to add all the pictures and then at the end create the post
);
);
);
;









share|improve this question



























    up vote
    0
    down vote

    favorite












    I have a file input from which I add a series of images to an array called var immaginiPost = . I then want to get all of these images and add them to Firebase Storage and then once these are uploaded get also the title and content of a post from other two text inputs and create a post on Firebase Database where I also uplaod every downloadUrl for each image. I have a problem where I need to wait that all images have been uploaded to Storage and all downlaodUrls have been added to the var immaginiDownloadURL = array before creating the post and I can't figure this out. Thank you in advance.



     //Here create a new post
    function newPost()
    var postsStorageRef = firebase.storage().ref().child('posts');
    var postDatabaseRef = firebase.database().ref().child('posts');
    var postKey = firebase.database().ref().child('posts').push().key;
    immaginiPost.forEach(function(file)
    let uploadTask = postsStorageRef.child(postKey).child(file.name).put(file);

    uploadTask.on('state_changed', function(snapshot)
    // Observe state change events such as progress, pause, and resume
    // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
    var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
    console.log('Upload is ' + progress + '% done');
    switch (snapshot.state)
    case firebase.storage.TaskState.PAUSED: // or 'paused'
    console.log('Upload is paused');
    break;
    case firebase.storage.TaskState.RUNNING: // or 'running'
    console.log('Upload is running');
    break;

    , function(error)
    // Handle unsuccessful uploads
    console.log('Unsuccessful upload');
    , function()
    // Handle successful uploads on complete
    // For instance, get the download URL: https://firebasestorage.googleapis.com/...
    uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL)
    console.log('File available at', downloadURL);
    immaginiDownloadUrl.push(downloadURL);
    //Then create the post...
    //TODO: Think of how to add all the pictures and then at the end create the post
    );
    );
    );
    ;









    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a file input from which I add a series of images to an array called var immaginiPost = . I then want to get all of these images and add them to Firebase Storage and then once these are uploaded get also the title and content of a post from other two text inputs and create a post on Firebase Database where I also uplaod every downloadUrl for each image. I have a problem where I need to wait that all images have been uploaded to Storage and all downlaodUrls have been added to the var immaginiDownloadURL = array before creating the post and I can't figure this out. Thank you in advance.



       //Here create a new post
      function newPost()
      var postsStorageRef = firebase.storage().ref().child('posts');
      var postDatabaseRef = firebase.database().ref().child('posts');
      var postKey = firebase.database().ref().child('posts').push().key;
      immaginiPost.forEach(function(file)
      let uploadTask = postsStorageRef.child(postKey).child(file.name).put(file);

      uploadTask.on('state_changed', function(snapshot)
      // Observe state change events such as progress, pause, and resume
      // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
      var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
      console.log('Upload is ' + progress + '% done');
      switch (snapshot.state)
      case firebase.storage.TaskState.PAUSED: // or 'paused'
      console.log('Upload is paused');
      break;
      case firebase.storage.TaskState.RUNNING: // or 'running'
      console.log('Upload is running');
      break;

      , function(error)
      // Handle unsuccessful uploads
      console.log('Unsuccessful upload');
      , function()
      // Handle successful uploads on complete
      // For instance, get the download URL: https://firebasestorage.googleapis.com/...
      uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL)
      console.log('File available at', downloadURL);
      immaginiDownloadUrl.push(downloadURL);
      //Then create the post...
      //TODO: Think of how to add all the pictures and then at the end create the post
      );
      );
      );
      ;









      share|improve this question















      I have a file input from which I add a series of images to an array called var immaginiPost = . I then want to get all of these images and add them to Firebase Storage and then once these are uploaded get also the title and content of a post from other two text inputs and create a post on Firebase Database where I also uplaod every downloadUrl for each image. I have a problem where I need to wait that all images have been uploaded to Storage and all downlaodUrls have been added to the var immaginiDownloadURL = array before creating the post and I can't figure this out. Thank you in advance.



       //Here create a new post
      function newPost()
      var postsStorageRef = firebase.storage().ref().child('posts');
      var postDatabaseRef = firebase.database().ref().child('posts');
      var postKey = firebase.database().ref().child('posts').push().key;
      immaginiPost.forEach(function(file)
      let uploadTask = postsStorageRef.child(postKey).child(file.name).put(file);

      uploadTask.on('state_changed', function(snapshot)
      // Observe state change events such as progress, pause, and resume
      // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
      var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
      console.log('Upload is ' + progress + '% done');
      switch (snapshot.state)
      case firebase.storage.TaskState.PAUSED: // or 'paused'
      console.log('Upload is paused');
      break;
      case firebase.storage.TaskState.RUNNING: // or 'running'
      console.log('Upload is running');
      break;

      , function(error)
      // Handle unsuccessful uploads
      console.log('Unsuccessful upload');
      , function()
      // Handle successful uploads on complete
      // For instance, get the download URL: https://firebasestorage.googleapis.com/...
      uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL)
      console.log('File available at', downloadURL);
      immaginiDownloadUrl.push(downloadURL);
      //Then create the post...
      //TODO: Think of how to add all the pictures and then at the end create the post
      );
      );
      );
      ;






      javascript html html5 firebase firebase-storage






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 11:50









      KENdi

      5,6992821




      5,6992821










      asked Nov 11 at 20:56









      Alessandro Thegreg

      247




      247



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253149%2fupload-multiple-images-on-firebase-storage-and-then-create-post%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253149%2fupload-multiple-images-on-firebase-storage-and-then-create-post%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto