Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
/ vue-file-upload Public archive

A file management system built with Vue.js and TypeScript that allows for single and multiple file uploading with a preview feature

License

Notifications You must be signed in to change notification settings

canopas/vue-file-upload

Repository files navigation

File Management with Preview - Fully Customized

A versatile and user-friendly 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.

Checkout the live demo on, codesandbox
codesandbox.io


Table of Contents


Features

  • Single File Upload:Users can upload or change a single file.
  • Multiple File Management:Easily manage multiple files.
  • File Preview:Provides a preview of uploaded files (e.g., images, videos, gifs).
  • Responsive Design:Ensures a seamless experience on various devices.
  • Fully customized:Customize file upload UI as per your requirements

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

Examples

We are providing some examples with design. so, you can easily take it and use into your project.

Canvas View

view code

Square View

view code

Horizontal Long Square View

view code

Circular View

view code

Over-ride CSS

For over-riding the design of default buttons, you can over-ride it's CSS by class name.
For example.,

  • Over-ride CSS of remove file button you can add it like,
.remove-btn{
color:white;
background-color:red;
font-size:25px;
padding:5px;
}
  • Over-ride CSS of submit/upload file button you can add it like,
.upload-btn{
color:white;
background-color:rgb(51,65,85);
font-size:25px;
padding:5px10px;
}

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'

Creating custom UI with file preview

  • You can customize file uploading UI intemplateblock.

  • Thefileslot containingfileobject 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

<divclass= "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"
>
<templatev-slot= "file">
<!-- write a code to manage file design or use code from examples -->
</template>
</SingleFileUpload>
</div>
<scriptlang="ts">
import{SingleFileUpload}from '@canopassoftware/vue-file-upload'

export default{
components:{
SingleFileUpload
},
data(){
return{
uploadedFile:{}as{
fileType:string
fileUrl:string
fileName:string
}
}
},
methods:{
asynchandleFileUploading(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

awaitnewPromise((resolve)=>setTimeout(resolve,2000))
},
}
}
</script>

Multiple File Upload Management

<divclass= "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"
>
<templatev-slot= "file">
<!-- write a code to manage file design or use code from examples -->
</template>
</MultipleFileUpload>
</div>
<scriptlang="ts">
import{MultipleFileUpload}from '@canopassoftware/vue-file-upload'

export default{
components:{
MultipleFileUpload
},
data(){
return{
uploadedFiles:[]asArray<{
fileType:string
fileUrl:string
fileName:string
}>
}
},
methods:{
asynchandleFilesUploading(files:any){
// add your fileuploading to server logic and set data to the uploadedFiles
this.uploadedFiles=[]
for(vari=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>

Contributing

We welcome contributions from the community. To contribute to this project, please follow these guidelines:

  • Fork the repository.
  • Create a new branch for your feature or bug fix.
  • Make your changes and commit them.
  • Push your changes to your fork.
  • Submit a pull request with a clear description of your changes.
  • Please ensure your code follows the project's coding standards and includes appropriate documentation.

License

This project is licensed under theMIT.

Contact Information

Vue file upload is owned and maintained by theCanopas team.You can reach out them on Github atcanopasfor questions or need support.