html5 - How does FileReader read multiple files at once?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-06-07 09:24:35
0
1
781
<input type="file" name="sendfile" id="sendfile" v-show='false' accept="image/png,image/gif,image/jpeg" @change='upload' multiple>

As above, for an input that supports multiple image uploads, how to use filereader to locally read the dataurl of each image? How to write this upload?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(1)
左手右手慢动作

Loop reading

new Vue({
  el: 'app',
  methods: {
    async upload () {
      const files = event.target.files
      const uploadList = []
      console.log(files)

      const readFileAsync = file => new Promise(resolve => {
        const reader = new FileReader()
        reader.onload = evt => resolve(evt.target.result)
        reader.readAsDataURL(file)
      })

      for (let i = 0; i < files.length; i++) {
        uploadList.push(await readFileAsync(files[i]))
      }

      event.target.value = null

      console.log(uploadList)
    }
  }
})
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template