0

vuetify:

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

How can I encode the file to base64?

2
  • Well, I do not know what variable contains my file object. orderattachment contains: lastModified: 1575018339000 ​​ name: "boarding-pass.pdf" ​​ size: 192624 ​​ type: "application/pdf" ​​ webkitRelativePath: "" So is this the variable I need to convert? Commented Feb 5, 2020 at 14:19
  • 1
    The return type from the Change event for v-file-input is File[] - which is just an array of File objects. You can see this in the documentation by selecting Events in the API section and looking for the Change event: vuetifyjs.com/en/components/file-inputs. So in short, yes, that's what you'd need to convert. Commented Feb 5, 2020 at 14:30

1 Answer 1

1

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)
    }
  },
Sign up to request clarification or add additional context in comments.

Comments

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.