npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@canopassoftware/vue-file-upload

v1.0.8

Published

Show the preview of file and manage files data to upload

Downloads

1,358

Readme

Vue File Management with Preview - Fully Customized

Vue file management system built with Vue.js and TypeScript that allows for single and multiple file uploading with a preview feature. It allows you to select files and preview them, returning an array of selected files. It allows customizing design by overriding the style classes.


Table of Contents


Getting Started

Follow below instructions to configure this package into your project.

Prerequisites

Before you begin, make sure you have the following software installed:

Installation

Using npm:

npm install @canopassoftware/vue-file-upload

Using yarn:

yarn add @canopassoftware/vue-file-upload

Properties and Events

props

  • :callback="handleFileUploading"

    • required
    • Description: Add your upload callback function while receive the selected file/files
  • :uploadedFile="uploadedFile" - For single file component

    • required
    • Uploaded file object with below format,
      {
        fileType: string,
        fileUrl: string,
        fileName: string
      }
  • :uploadedFiles="uploadedFiles" - For multiple file component

    • required
    • Uploaded files array with below format,
      [
        {
          fileType: string,
          fileUrl: string,
          fileName: string
        }
      ]
  • :uploadBtnText="'Upload'"

    • default : Upload
    • Text for save or upload file button
  • :progressBtnText="'Uploading...'"

    • default : Uploading...
    • Text for the progress bar, showing file uploading under the process
  • :removeBtnText="'Uploading...'"

    • default : x
    • Text for remove file button
  • :accept="'image/jpg, image/jpeg, image/png, video/mp4, audio/mp3, application/zip'"

    • Validation for file type. By default it will select all the type of file.
  • :(filetype)Preview="'(file location)'"

    • default : Default file icons as per file types
    • Set path for your customized icon if needed

Usage

To manage and preview files with this library, follow these steps:

Import the library into your file

// using CommonJS
const { SingleFileUpload, MultipleFileUpload } = require('@canopassoftware/vue-file-upload')

OR
// using esModules
import { SingleFileUpload, MultipleFileUpload } from '@canopassoftware/vue-file-upload'

Use default CSS

  • Use style.css for UI by importing like,
import "@canopassoftware/vue-file-upload/style.css"

Creating custom UI with file preview

  • You can customize file uploading UI in template block.

  • The file slot containing file object with following keys, we will use this object to show preview.

    file = file: {
      previewType: 'video', // type of the preview. like, file is image or video
      previewUrl: 'data:image/jpeg;base64,/9j/D1AAAACRsdW1pAAAD...', // URL of the file preview
      previewName: 'a152148640581.62d918f12a0b4.mp4', // preview file name
      isDragging: false // you will get it `true` when you dragging the file on design
    }

Single File Upload Management

<div class="flex flex-wrap">
  <SingleFileUpload
    :uploadBtnText="'Upload'"
    :progressBtnText="'Uploading...'"
    :isUploading="isUploading"
    :accept="'image/jpg, image/jpeg, image/png, video/mp4, audio/mp3, application/zip'"
    :pdfPreview="'../assets/images/pdf-icon.png'"
    :textPreview="'../assets/images/text-icon.png'"
    :audioPreview="'../assets/images/music-icon.png'"
    :apkPreview="'../assets/images/apk-icon.png'"
    :zipPreview="'../assets/images/zip-icon.png'"
    :sqlPreview="'../assets/images/sql-icon.png'"
    :filePreview="'../assets/images/file-icon.png'"
    :uploadedFile="uploadedFile"
    :callback="handleFileUploading"
  >
    <template v-slot="file">
      <!-- write a code to manage file design or use code from examples -->
    </template>
  </SingleFileUpload>
</div>
<script lang="ts">
import { SingleFileUpload } from '@canopassoftware/vue-file-upload'

export default {
  components: {
    SingleFileUpload
  },
  data() {
    return {
      uploadedFile: {} as {
        fileType: string
        fileUrl: string
        fileName: string
      }
    }
  },
  methods: {
    async handleFileUploading(file: any) {
      // add your fileuploading logic to server and set data to the uploadedFile
      this.uploadedFile.fileType = 'image'
      this.uploadedFile.fileUrl = 'https://picsum.photos/300/224'
      this.uploadedFile.fileName = file.name

      await new Promise((resolve) => setTimeout(resolve, 2000))
    },
  }
}
</script>

Multiple File Upload Management

<div class="flex flex-wrap">
  <MultipleFileUpload
    :removeBtnText="'remove'"
    :uploadBtn="'Upload'"
    :progressBtnText="'Uploading...'"
    :accept="'image/jpg, image/jpeg, image/png, video/mp4, audio/mp3, application/zip'"
    :pdfPreview="'../assets/images/pdf-icon.png'"
    :textPreview="'../assets/images/text-icon.png'"
    :audioPreview="'../assets/images/music-icon.png'"
    :apkPreview="'../assets/images/apk-icon.png'"
    :zipPreview="'../assets/images/zip-icon.png'"
    :sqlPreview="'../assets/images/sql-icon.png'"
    :filePreview="'../assets/images/file-icon.png'"
    :uploadedFiles="uploadedFiles"
    :callback="handleFilesUploading"
  >
    <template v-slot="file">
      <!-- write a code to manage file design or use code from examples -->
    </template>
  </MultipleFileUpload>
</div>
<script lang="ts">
import { MultipleFileUpload } from '@canopassoftware/vue-file-upload'

export default {
  components: {
    MultipleFileUpload
  },
  data() {
    return {
      uploadedFiles: [] as Array<{
        fileType: string
        fileUrl: string
        fileName: string
      }>
    }
  },
  methods: {
    async handleFilesUploading(files: any) {
      // add your fileuploading to server logic and set data to the uploadedFiles
      this.uploadedFiles = []
      for (var i = 0; i < files.length; i++) {
        this.uploadedFiles.push({
          fileType: 'image',
          fileUrl: 'https://picsum.photos/300/224',
          fileName: files[i].name
        })
      }

      await new Promise((resolve) => setTimeout(resolve, 2000))
    }
  }
}
</script>