3.1.7 • Published 5 years ago

v-file-upload v3.1.7

Weekly downloads
1,051
License
MIT
Repository
github
Last release
5 years ago

v-file-upload

File upload component for Vue.js

Installation

Using yarn

yarn add v-file-upload

Using npm

npm i --save v-file-upload

Demo

DEMO

Usage

As component

import Vue from 'vue'

import FileUpload from 'v-file-upload'

Vue.use(FileUpload)

As service

import { FileUploadService } from 'v-file-upload'

Examples

As component

<template>
  <file-upload :url='url' :thumb-url='thumbUrl' :headers="headers" @change="onFileChange"></file-upload>
</template>

<script>
import Vue from 'vue'
import FileUpload from 'v-file-upload'
Vue.use(FileUpload)

export default {
  data () {
    return {
      url: 'http://your-post.url',
      headers: {'access-token': '<your-token>'},
      filesUploaded: []
    }
  },
  methods: {
    thumbUrl (file) {
      return file.myThumbUrlProperty
    },
    onFileChange (file) {
      // Handle files like:
      this.fileUploaded = file
    }
  }
}
</script>

Properties

NameTypeRequiredDefaultInfo
urlStringTrueUrl to POST the files
thumb-urlFunctionTrueMethod that should returns the thumb url for the uploaded file
acceptStringFalse.png,.jpgFile input accept filter
headersObjectFalse{}Headers for the request. You can pass auth tokens for example
btn-labelStringFalseSelect a fileLabel for the button
btn-uploading-labelStringFalseUploading filesLabel for the button when the upload is in progress
max-sizeNumberFalse15728640 //15MbMax size for the file
additional-dataObjectFalse{}Additional data for the request

Events

NameParamsInfo
successevent: XMLHttpRequest eventTriggered after POST success
errorevent: XMLHttpRequest eventTriggered after POST error
changefiles: Array of uploaded filesTriggered after add or remove a file
progressprogress: Progress percentageTriggered while the upload is in progress indicating the upload percentage

As service

import { FileUploadService } from 'v-file-upload'
export default {
  data() {
    return {
      url: 'http://your-post.url',
      headers: { 'access-token': '<your-token>' }
    }
  },
  methods: {
    mySaveMethod(file) {
      let fileUpload = new FileUploadService(
        this.url,
        this.headers,
        this.onProgress
      )
      fileUpload
        .upload(file, { doc_id: 1 })
        .then(e => {
          // Handle success
        })
        .catch(e => {
          // Handle error
        })
    },
    onProgress(event) {
      // Handdle the progress
    }
  }
}

Development

yarn dist

Author

License

This project is licensed under MIT License

3.1.7

5 years ago

3.1.6

5 years ago

3.1.5

5 years ago

3.1.4

5 years ago

3.1.3

6 years ago

3.1.2

6 years ago

3.1.1

6 years ago

3.1.0

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago