Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

302
Visualizações
How to show the file name while we are uploading multiple images

Here I have written the vue.js code for multi upload with single input field.

And this is working exactly fine But the issue is while we are uploading the file it is showing the number of files uploaded but instead i want to display the name of the file what we are uploading.

So can we do this please let me know.

<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>
<template id="asad">
    <div class="container">
        <div>
            <h2>Multiple Files</h2>
            <hr/>
            <label>Files
                <input type="file" multiple @change="handleFileUploads( $event )"/>
            </label>
            <br>
            <button v-on:click="submitFiles()">Submit</button>
        </div>
    </div>
</template>
</body>

<script>
    var app = new Vue({
    el: '#asad',
        data(){
            return {
                files: []
            }
        },
        
        methods: {
            handleFileUpload( event ){
                this.files = event.target.files;
            },
            
            submitFile(){
                let formData = new FormData();
                
                for( var i = 0; i < this.files.length; i++ ){
                    let file = this.files[i];
                
                    formData.append('files[' + i + ']', file);
                }
                
                axios.post( '/multiple-files',
                    formData,
                    {
                        headers: {
                                'Content-Type': 'multipart/form-data'
                        }
                    }
                ).then(function(){
                    console.log('SUCCESS!!');
                })
                .catch(function(){
                    console.log('FAILURE!!');
                });
            }
        }
    })
</script>
</html>

image

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can try with computed property :

<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="asad">
<template >
    <div class="container">
        <div>
            <h2>Multiple Files</h2>
            <hr/>
            <label>Files
                <input type="file" multiple @change="handleFileUploads( $event )"/>
                <ul v-if="files.length">
                <li v-for="(name, i) in filesNames" :key="i">{{ name }}</li>
                </ul>
            </label>
            
            <br>
            <button v-on:click="submitFiles()">Submit</button>
        </div>
    </div>
</template>
</div>
</body>

<script>
var app = new Vue({
  el: '#asad',
  data(){
    return {
      files: []
    }
  },
  computed: {
    filesNames() {
      const fn = []
      for (let i = 0; i < this.files.length; ++i) {
        fn.push(this.files.item(i).name)
      }
      return fn
    }
  }, 
  methods: {
    handleFileUploads( event ){
      this.files = event.target.files;
    },

    submitFile(){
      let formData = new FormData();
      for( var i = 0; i < this.files.length; i++ ){
        let file = this.files[i];
        formData.append('files[' + i + ']', file);
      }
      axios.post( '/multiple-files', formData, 
        {headers: {'Content-Type': 'multipart/form-data'}}
      ).then(function(){
        console.log('SUCCESS!!');
      })
      .catch(function(){
        console.log('FAILURE!!');
      });
    }
  }
})
  
</script>
</html>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda