Gathering detailed insights and metrics for vue-media-upload
Gathering detailed insights and metrics for vue-media-upload
Gathering detailed insights and metrics for vue-media-upload
Gathering detailed insights and metrics for vue-media-upload
🖼️ Vue 3 component that handle multiple images upload with preview. This package support the create and the update form.
npm install vue-media-upload
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
207 Stars
28 Commits
33 Forks
4 Watching
1 Branches
2 Contributors
Updated on 21 Nov 2024
Vue (99.37%)
JavaScript (0.63%)
Cumulative downloads
Total Downloads
Last day
16.9%
76
Compared to previous day
Last week
20.8%
371
Compared to previous week
Last month
18.6%
1,387
Compared to previous month
Last year
-4.2%
16,833
Compared to previous year
No dependencies detected.
📷 vue-media-upload is a Vuejs package that handle multiple images upload and preview.
🖼️ This package support the create and the update form, and handles the upload for you.
via npm
1npm install vue-media-upload
or via yarn
1yarn add vue-media-upload
1import { createApp } from 'vue'; 2 3import Uploader from 'vue-media-upload'; 4 5let app = createApp({}) 6 7app.component('Uploader', Uploader); 8 9app.mount("#app")
or
1import Uploader from "vue-media-upload"; 2 3export default { 4 components: { 5 Uploader 6 } 7};
1<template> 2 <div> 3 <Uploader 4 server="/api/upload" 5 @change="changeMedia" 6 /> 7 </div> 8</template> 9 10<script> 11 import Uploader from 'vue-media-upload' 12 13 export default { 14 data() { 15 return { 16 media: [] 17 } 18 }, 19 methods:{ 20 changeMedia(media){ 21 this.media = media 22 } 23 }, 24 components: { 25 Uploader 26 }, 27 } 28</script>
1<template> 2 <div> 3 <Uploader 4 server="/api/upload" 5 :media="media.saved" 6 path="/storage/media" 7 @add="addMedia" 8 @remove="removeMedia" 9 /> 10 </div> 11</template> 12 13<script> 14 import Uploader from 'vue-media-upload' 15 16 export default { 17 data() { 18 return { 19 media: { 20 saved: [ 21 { name: '123_image.jpg' }, 22 { name: '456_image.jpg' }, 23 ], 24 added: [], 25 removed: [] 26 } 27 } 28 }, 29 methods:{ 30 addMedia(addedImage, addedMedia){ 31 this.media.added = addedMedia 32 }, 33 removeMedia(removedImage, removedMedia){ 34 this.media.removed = removedMedia 35 } 36 }, 37 components: { 38 Uploader 39 }, 40 } 41</script>
Prop | Type | Default | Description |
---|---|---|---|
server | String | '/api/upload' | The Route that handle the image upload. The Upload handler should return the name of the uploaded image in the following format: { "name": "123_image.jpg" } |
isInvalid | Boolean | false | Whether error styling should be applied. |
media | Array | [] | The list of the stored images, that each of which must have the property name containing the name of the image. [ { name: '123_image.jpg' } , { name: '456_image.jpg' } ] |
location | String | '' | The location of the folder where the saved images are stored. |
max | Number | null | The maximum number of files allowed to be uploaded. |
maxFilesize | Number | 4 | The maximum filesize (in megabytes) that is allowed to be uploaded |
warnings | Boolean | true | By default, the package uses JavaScript alerts to display warnings. In case you want to use your custom warnings, you can disable the component pop-ups using this prop. |
headers | Object | null | An optional prop to send additional headers to the server. Eg: { "Authorization": "Bearer ACCESS_TOKEN" } |
Event | Payload | Description |
---|---|---|
@init | param : The list of all the listed images. | Emitted when the component is ready to use. |
@change | param : The list of all the listed images. | Emitted after an image was added or removed. |
@add | param1 : The image that was added. param2 : The list of the added Images. | Emitted after an image was added. |
@remove | param1 : The image that was removed. param2 : The list of images that have been removed from the stored media. | Emitted after an image was removed. |
@max | Emitted when max prop is exceeded. | |
@max-filesize | param : The image size. | Emitted when maxFilesize prop is exceeded. |
vue-media-upload component uploads the image image.jpg
as multipart/form-data using a POST request.
server temporary saves the image with a unique name 123_image.jpg
in a /tmp/uploads
folder.
server returns the unique name 123_image.jpg
in a request response.
vue-media-upload insert the unique name 123_image.jpg
in a hidden html input with name="added_media[]"
.
user submits the component parent form, which includes the hidden input field containing the unique image name.
server uses the unique image name to move 123_image.jpg
from the /tmp/uploads
folder to its final location.
Note that all this inputs are hidden and they are just a way to validate and pass data to the backend when using this package in a Server-Rendered Form!
Name attribute | Description |
---|---|
added_media[] | The added images in the component |
removed_media[] | The images that have been removed from the stored media. |
media | This input is added, when the component has at least one image or more listed, as a way for the backend to validate the Images as being required. |
If you like this project, You can support me with starring ⭐ this repository.
Developed with ❤️
No vulnerabilities found.
No security vulnerabilities found.