├── .editorconfig ├── .gitignore ├── .jshintrc ├── LICENSE ├── README.md ├── example.html ├── gulpfile.js ├── package.json ├── upload.php ├── vue.file-upload.js └── vue.pretty-bytes.js /.editorconfig: -------------------------------------------------------------------------------- 1 | ; top-most EditorConfig file 2 | root = true 3 | 4 | ; Unix-style newlines with a newline ending every file 5 | [*] 6 | end_of_line = lf 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 2 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # go away osx file 2 | .DS_Store 3 | 4 | # Logs 5 | logs 6 | *.log 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | 13 | # Directory for instrumented libs generated by jscoverage/JSCover 14 | lib-cov 15 | 16 | # Coverage directory used by tools like istanbul 17 | coverage 18 | 19 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 20 | .grunt 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # Commenting this out is preferred by some people, see 27 | # https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 28 | node_modules 29 | 30 | # Users Environment Variables 31 | .lock-wscript 32 | 33 | # workspace files are user-specific 34 | *.sublime-workspace 35 | 36 | # project files should be checked into the repository, unless a significant 37 | # proportion of contributors will probably not be using SublimeText 38 | # *.sublime-project 39 | 40 | #sftp configuration file 41 | sftp-config.json 42 | 43 | uploads/* 44 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | // Settings 3 | "passfail": false, // Stop on first error. 4 | "maxerr": 100, // Maximum error before stopping. 5 | // Predefined globals whom JSHint will ignore. 6 | "browser": true, // Standard browser globals e.g. `window`, `document`. 7 | "node": false, 8 | "rhino": false, 9 | "couch": false, 10 | "wsh": true, // Windows Scripting Host. 11 | "jquery": true, 12 | "ender": true, 13 | "prototypejs": false, 14 | "mootools": false, 15 | "dojo": false, 16 | "predef": [ // Custom globals. 17 | "Modernizr" 18 | //"anotherCoolGlobal", 19 | //"iLoveDouglas" 20 | ], 21 | // Development. 22 | "debug": false, // Allow debugger statements e.g. browser breakpoints. 23 | "devel": true, // Allow developments statements e.g. `console.log();`. 24 | // ECMAScript 5. 25 | "es5": true, // Allow ECMAScript 5 syntax. 26 | "strict": false, // Require `use strict` pragma in every file. 27 | "globalstrict": false, // Allow global "use strict" (also enables 'strict'). 28 | // The Good Parts. 29 | "asi": true, // Tolerate Automatic Semicolon Insertion (no semicolons). 30 | "laxbreak": true, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons. 31 | "bitwise": true, // Prohibit bitwise operators (&, |, ^, etc.). 32 | "boss": false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments. 33 | "curly": true, // Require {} for every new block or scope. 34 | "eqeqeq": false, // Require triple equals i.e. `===`. 35 | "eqnull": false, // Tolerate use of `== null`. 36 | "evil": false, // Tolerate use of `eval`. 37 | "expr": false, // Tolerate `ExpressionStatement` as Programs. 38 | "forin": false, // Tolerate `for in` loops without `hasOwnPrototype`. 39 | "immed": true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );` 40 | "latedef": true, // Prohipit variable use before definition. 41 | "loopfunc": false, // Allow functions to be defined within loops. 42 | "noarg": false, // Prohibit use of `arguments.caller` and `arguments.callee`. 43 | "regexp": true, // Prohibit `.` and `[^...]` in regular expressions. 44 | "regexdash": false, // Tolerate unescaped last dash i.e. `[-...]`. 45 | "scripturl": true, // Tolerate script-targeted URLs. 46 | "shadow": false, // Allows re-define variables later in code e.g. `var x=1; x=2;`. 47 | "supernew": false, // Tolerate `new function () { ... };` and `new Object;`. 48 | "undef": true, // Require all non-global variables be declared before they are used. 49 | 50 | // Personal styling preferences. 51 | "newcap": true, // Require capitalization of all constructor functions e.g. `new F()`. 52 | "noempty": true, // Prohibit use of empty blocks. 53 | "nonew": true, // Prohibit use of constructors for side-effects. 54 | "nomen": true, // Prohibit use of initial or trailing underbars in names. 55 | "onevar": false, // Allow only one `var` statement per function. 56 | "plusplus": false, // Prohibit use of `++` & `--`. 57 | "sub": false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`. 58 | "trailing": true, // Prohibit trailing whitespaces. 59 | "white": false, // Check against strict whitespace and indentation rules. 60 | "indent": 2 // Specify indentation spacing 61 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 James Doyle 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-file-upload-component 2 | 3 | A simple file upload component for Vue.js. Emits events for XHR Upload Progress for nice progress bars. 4 | 5 | I came up with the original idea when looking at [this repo](https://github.com/tj/s3.js). I knew I wanted a nice component with upload progress and so I copied some code from that library. 6 | 7 | ### Install 8 | 9 | Available through npm as `vue-file-upload-component`. Or include as an inline script, like in `example.html`. 10 | 11 | ### Demo 12 | 13 |  14 | 15 | In order to use the demo, you need to have PHP setup and this project running under a server. There is a script in the root called `upload.php`, which is a simple script to handle single file uploads. Most likely you will have your own way of handling files. 16 | 17 | ### Setting Headers 18 | 19 | You can set headers for the submission by using the attribute `v-bind:headers="xhrHeaders"`. `xhrHeaders` may look something like this: 20 | 21 | ```json 22 | // ... Vue stuff above 23 | data: { 24 | xhrHeaders: { 25 | "X-CSRF-TOKEN": "32charactersOfRandomStringNoise!" 26 | } 27 | }, 28 | // ... more stuff below 29 | ``` 30 | 31 | You can set many headers in the object. 32 | 33 | ### Caveats 34 | 35 | This upload script only uploads 1 file at a time. The upload handler uses `Promises` internally to know when all the files are uploaded. 36 | 37 | If you are using Internet Explorer, you will probably need a polyfill. I have [used this one before](https://github.com/getify/native-promise-only) and it is small and well tested. 38 | 39 | You also need [support for FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) but it has higher support than `Promises` so you are probably fine. 40 | -------------------------------------------------------------------------------- /example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |All Files Uploaded
28 | 29 |