1.0.5 • Published 4 years ago

shapla-file-uploader v1.0.5

Weekly downloads
7
License
MIT
Repository
github
Last release
4 years ago

shapla-file-uploader

A collection of vue component for handling frontend drag and drop file upload functionality.

Table of contents

Installation

npm install --save shapla-file-uploader

Usage

Add the component:

import FileUploader from 'shapla-file-uploader';

export default {
  name: 'Hello',

  components: {
    FileUploader
  },
  
  methods: {
    handleSuccess(fileObject,serverResponse){
      // Handle click event
    }
  }
}
<file-uploader @success="handleSuccess"></file-uploader>

Props

PropertyTypeRequiredDefaultDescription
urlStringyesnullFile upload url
methodStringnoPOSTFile upload method
paramNameStringnofileFile upload parameter name
textLineOneStringnoDrag &amp; drop filesPlaceholder first line text
textLineTwoStringnoorPlaceholder second line text
textButtonStringnoSelect files to uploadButton text
textMaxUploadLimitStringnoMaximum upload file size: 2MBMax upload limit text
inputIdStringnoshapla-file-uploader__inputInput field id to make it unique. You must set inputId if you are using multiple instance in a same page.
paramsObjectno{}An object of additional parameters to transfer to the server
showFileUploadStatusBooleannotrueIf set true, individual file upload status will be shown
showFilesUploadStatusBooleannotrueIf set true, all files upload status will be shown

Listeners

The uploader component fires the following events:

init: It fires the event when a file initiate to upload. FormData pass as parameter.

before:send: It fires the event before sending data to server. XMLHttpRequest pass as first parameter and FormData pass as second parameter.

progress: It fires the event when a file upload in progress. fileObject object pass as first parameter and event pass as second parameter.

success: It fires the event when a file uploaded successfully. fileObject object pass as first parameter and serverResponse pass as second parameter.

failed: It fires the event when a file uploaded failed on server. fileObject object pass as first parameter and serverResponse pass as second parameter.

error: It fires the event when a file uploaded failed. fileObject object pass as first parameter.

<!-- template -->
<file-uploader 
    @before:send="handleBeforeSendEvent"
    @success="handleSuccess"
/>

<!-- method -->
methods: {
    handleBeforeSendEvent(xhr,formData){
        // You can add custom header to xhr
        xhr.setRequestHeader('Authorization', 'authorization code goes here');
    },
    handleSuccess(fileObject,serverResponse){
        // Handle click event
    }
}
1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago