0

I am wondering how to use FileReader in vue js if I have to get images upload from two or more different input fields (tags). I have been copying and pasting the same code below to different functions in order to upload files but i think that there should be a better way.

bImage(event) {
      let file = event.target.files[0];
      let reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload = event => {
        this.form.images.push(event.target.result);
        console.log(event.target.result);
      };
    },
Phil
  • 157,677
  • 23
  • 242
  • 245
  • 1
    This can be found on stackoverflow already on: https://stackoverflow.com/questions/13975031/reading-multiple-files-with-javascript-filereader-api-one-at-a-time – Chris Jun 03 '20 at 14:33
  • No, no I know how to add multiple images but I am having problem when i use filereader for uploading files from different input fields inside a same form. Although I have five input fields for file, the image data gets bound to only one input field and other remain unchanged, Can you help me? – Bimal Subedi Jun 05 '20 at 04:20
  • 1
    Whats the issue? Above should work? – Estradiaz Jun 05 '20 at 04:51
  • @Estradiaz The above code worked but if i use more than two input fields for file upload only one data gets the value of filereader output, others remain empty. – Bimal Subedi Jun 05 '20 at 13:19
  • hmm maybe show us your implementation of whats not working then? how do you use it on more? – Estradiaz Jun 05 '20 at 13:31

0 Answers0