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);
      };
    },
5
  • 1
    This can be found on stackoverflow already on: stackoverflow.com/questions/13975031/… Commented Jun 3, 2020 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? Commented Jun 5, 2020 at 4:20
  • 1
    Whats the issue? Above should work? Commented Jun 5, 2020 at 4: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. Commented Jun 5, 2020 at 13:19
  • hmm maybe show us your implementation of whats not working then? how do you use it on more? Commented Jun 5, 2020 at 13:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.