farahm
farahm

Reputation: 1326

Encode file to base64 in v-file-input vuejs and vuetify

vuetify:

 <v-file-input 
     multiple 
     label="Angebotsdokumente" 
     v-model="orderattachment">
</v-file-input>

How can I encode the file to base64?

Upvotes: 0

Views: 2538

Answers (1)

Alan Spurlock
Alan Spurlock

Reputation: 343

Easy.

  1. Put a watch on your v-model object "orderattachment"
  2. Run FileReader() on it and output the base64
watch: {
    orderattachment(value) {
      console.log("value", value)
      let fr = new FileReader()
      fr.addEventListener("load", function (e) {
        //this is your base64
        console.log(e.target.result)
      });
      fr.readAsDataURL(value)
    }
  },

Upvotes: 1

Related Questions