1

I have a Vuetify fie input:

<v-file-input
  accept="text/csv"
  label="File input"
  placeholder="Select your CSV files"
></v-file-input>

I want to upload only CSV files, but the accept="text/csv" not working, I can upload any file,

I have test other type like accept="image/*" and its work.


https://codepen.io/AiAbdrahim/pen/oNLyYvm


new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  
})
<script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet"/>
<link href="https://cdn.jsdelivr.net/npm/@mdi/[email protected]/css/materialdesignicons.min.css" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css?family=Material+Icons" rel="stylesheet"/>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css" rel="stylesheet"/>
<div id="app">
  <v-app id="inspire">
    <v-file-input
      accept="text/csv"
      label="File input"
      placeholder="Select your CSV files"
    ></v-file-input>
  </v-app>
</div>

3 Answers 3

2

You could try this something like this, it works on vue.

<input id="fileUpload" type="file" ref="inputFile" @input="myUploadFile()" hidden />

And write a setUploadFile method

myUploadFile(){
 this.file = this.$refs.inputFile.files[0];
 if (this.file.type == "text/csv"){
    // Api call
 }
 else {
   this.showAlert("error", "The file-type doesn't belong to text/csv")
 }
}
Sign up to request clarification or add additional context in comments.

Comments

1

It's not related to Vuetify. You have inserted a wrong accept value. html-input-file-accept-attribute-file-type-csv

Comments

0

You need also to include a rule preventing that:

<v-file-input
  accept="text/csv"
  :rules="(value) => !value || value.type == 'text/csv' || 'Only CSV files allowed'"
  label="File input"
  placeholder="Select your CSV files"
></v-file-input>

1 Comment

Rules must be an array, make it like, :rules="[(value) => !value || value.type == 'text/csv' || 'Only CSV files allowed]'"

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.