🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

v-file-upload

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

v-file-upload

File input component for Vue.js

latest
Source
npmnpm
Version
3.1.7
Version published
Maintainers
1
Created
Source

v-file-upload

File upload component for Vue.js

Downloads Version License

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

Keywords

vue

FAQs

Package last updated on 04 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts