├── .gitattributes ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── dist └── upload_image.vue ├── example └── images │ └── example.png └── package.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | 49 | #IDES 50 | .idea 51 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | #### 1.1.5 2 | * improved documentation 3 | * ability to disable automatic uploading (allowing for manual uploads) 4 | * added image loaded event (called after image fle has been read) 5 | * upload-image-loaded 6 | * added submit event (called after end-user has clicked on "submit" action) 7 | * upload-image-submit 8 | * added image clicked event (called when an image is clicked) 9 | * upload-image-clicked 10 | * added image removed event (called when an image has been removed) 11 | * upload-image-removed 12 | 13 | #### 1.1.2 14 | 15 | * README & LICENSE adjustments. 16 | 17 | #### 1.1.1 18 | 19 | * README & CHANGELOG adjustments. 20 | 21 | #### 1.1.0 22 | 23 | * resizing capabilities introduced. 24 | * events pass both FormData & result from request to parent. 25 | * bug fixes. 26 | * [[PULLED REQUEST](https://github.com/viral-vector/vue-upload-image/commit/20ba66f3126db0cc0ca14d2d45f26917d3ff50ba)] 27 | 28 | #### 1.0.0 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 viral-vector 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Latest Stable Version](https://img.shields.io/npm/v/vue-upload-image.svg)](https://www.npmjs.com/package/vue-upload-image) 2 | 3 | # vue-upload-image 4 | Configurable image uploader with preview 5 | 6 | + drag and drop with input backup 7 | + image previews 8 | + simple resizing 9 | + events 10 | + minimal 11 | + configurable 12 | 13 | ![example](example/images/example.png) 14 | 15 | ## Installation & Usage 16 | 17 | Vue.prototype.$http must be define, for automatic uploads to work. 18 | [info](https://medium.com/the-vue-point/retiring-vue-resource-871a82880af4#.z4rqh1qtp) 19 | 20 | * install the package 21 | ```bash 22 | npm install vue-upload-image --save 23 | ``` 24 | * import & register the component 25 | ```js 26 | import UploadImage from 'vue-upload-image'; 27 | 28 | // register globally 29 | Vue.component('upload-image', UploadImage) 30 | 31 | // or ... register locally 32 | new Vue({ 33 | ..., 34 | components: { 35 | UploadImage 36 | } 37 | }) 38 | ``` 39 | * add component to page 40 | ```html 41 | // html template 42 | 58 | 59 | // or set Vue instance template property 60 | { 61 | name: 'component or root Vue instance', 62 | template: '', 63 | props: ..., 64 | data: ... 65 | components: { 66 | UploadImage 67 | } 68 | } 69 | ``` 70 | 71 | ## Configuration 72 | ```js 73 | input_id: { // Id of upload control 74 | type: String, 75 | required: false, 76 | default: "default" 77 | }, 78 | url: { // upload url 79 | type: String, 80 | required: true, 81 | default: null 82 | }, 83 | name: { // name to use for FormData 84 | type: String, 85 | required: false, 86 | default: 'images[]' 87 | }, 88 | disable_upload: { // disable auto uploading 89 | type: Boolean, 90 | required: false, 91 | default: false 92 | }, 93 | max_batch: { // # of files to upload within one request 94 | type: Number, 95 | required: false, 96 | default: 0 97 | }, 98 | max_files: { // total # of files allowed to be uploaded 99 | type: Number, 100 | required: false, 101 | default: 10 102 | }, 103 | max_filesize: { // max files size in KB 104 | type: Number, 105 | required: false, 106 | default: 8000 107 | }, 108 | resize_enabled: { // resize image prior to preview/upload 109 | type: Boolean, 110 | required: false, 111 | default: false 112 | }, 113 | resize_max_width: { // resize max width 114 | type: Number, 115 | required: false, 116 | default: 800 117 | }, 118 | resize_max_height: { // resize max height 119 | type: Number, 120 | required: false, 121 | default: 600 122 | }, 123 | button_html: { // text/html for button 124 | type: String, 125 | required: false, 126 | default: 'Upload Images' 127 | }, 128 | button_class: { // classes for button 129 | type: String, 130 | required: false, 131 | default: 'btn btn-primary' 132 | } 133 | ``` 134 | 135 | ## UI/UX Adjustments 136 | 137 | * Basic look & feel can be adjusted via html/css classes 138 | ```css 139 | .vue_component__upload--image 140 | .upload_image_form__thumbnails 141 | .upload_image_form__thumbnail [&.bad-size, &.uploaded] 142 | .img [&.show, &:hover] 143 | span 144 | ``` 145 | 146 | ## Events 147 | * Event listeners can be added as such 148 | 149 | ```html 150 | 161 | ``` 162 | 163 | ```js 164 | { 165 | methods: { 166 | uploadImageSuccess: function(result){ 167 | result[0] // FormData 168 | result[1] // response 169 | }, 170 | uploadImageLoaded: function(image){ 171 | image.name || image.file 172 | }, 173 | uploadImageClicked: function(image){ 174 | image.name || image.file 175 | }, 176 | uploadImageRemoved: function(image){ 177 | image.name || image.file 178 | }, 179 | uploadImageSubmit: function(images){ 180 | } 181 | } 182 | } 183 | ``` 184 | 185 | * **upload-image-loaded** **-** [image] 186 | * event is called after an image has been fully loaded & rendered in preview area 187 | * emits an object containing the file name & blob of the image 188 | * **upload-image-clicked** **-** [image] 189 | * event is called when an image in preview has been clicked 190 | * emits an object containing the file name & blob of the image 191 | * **upload-image-removed** **-** [image] 192 | * event is called after an image has been removed from preview 193 | * emits an object containing the file name & blob of the image 194 | * **upload-image-submit** **-** [images] 195 | * event is called immediately after the end user triggers the "submit" action (button_html property) 196 | * emits a FormData object composed of images being uploaded 197 | * batched submissions will emit this event per batch 198 | * **can be utilized with disable_upload property for manual uploads** 199 | * **upload-image-attempt** **-** [FormData] 200 | * event is called prior to an automatic upload to the designated url 201 | * emits a FormData object composed of images being uploaded 202 | * batched submissions will emit this event per batch 203 | * **upload-image-success** **-** [FormData, Response] 204 | * event is called after s successful automatic upload to the designated url 205 | * emits a FormData object composed of images being uploaded along with the success response object from the server 206 | * **upload-image-failure** **-** [FormData, Response] 207 | * event is called after s failed automatic upload to the designated url 208 | * emits a FormData object composed of images being uploaded along with the error response object from the server 209 | 210 | 211 | ## License 212 | This project is licensed under the [MIT](http://vjpr.mit-license.org) License. 213 | 214 | ## Contributing Guidelines 215 | 216 | * All changes must be documented in [CHANGELOG.md](CHANGELOG.md) 217 | -------------------------------------------------------------------------------- /dist/upload_image.vue: -------------------------------------------------------------------------------- 1 | 25 | 26 | 336 | 337 | 404 | -------------------------------------------------------------------------------- /example/images/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viral-vector/vue-upload-image/32f2d8944ad249298b8d61d975e16f5f322ff050/example/images/example.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-upload-image", 3 | "version": "1.1.2", 4 | "description": "Configurable image preview & ajax up-loader", 5 | "main": "dist/upload_image.vue", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/viral-vector/vue-upload-image.git" 9 | }, 10 | "keywords": [ 11 | "vue-image-upload", 12 | "vue.js image uploader", 13 | "vue.js image", 14 | "vue image.js", 15 | "vue.js uploader", 16 | "vue.js", 17 | "image", 18 | "upload", 19 | "multiple", 20 | "component", 21 | "vue-component", 22 | "vue-upload-component" 23 | ], 24 | "author": { 25 | "name": "viral-vector", 26 | "email": "vectorviral@gmail.com" 27 | }, 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/viral-vector/vue-upload-image/issues" 31 | }, 32 | "homepage": "https://github.com/viral-vector/vue-upload-image", 33 | "dependencies": { 34 | 35 | } 36 | } --------------------------------------------------------------------------------