├── index.js ├── package.json ├── LICENSE.md └── README.md /index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const fileUpload = require('express-fileupload') 4 | 5 | exports.upload = function upload (opts, fn) { 6 | if (!fn) { 7 | fn = opts 8 | opts = {} 9 | } 10 | 11 | const handler = fileUpload(opts) 12 | 13 | return (req, res) => { 14 | return new Promise(resolve => handler(req, res, resolve)) 15 | .then(() => fn(req, res)) 16 | } 17 | } 18 | 19 | exports.move = function move (src, dst) { 20 | return new Promise((resolve, reject) => { 21 | if (!src || typeof src.mv !== 'function') { 22 | reject(new TypeError('First argument must be an upload file object')) 23 | } 24 | 25 | src.mv(dst, err => { 26 | if (err) return reject(err) 27 | 28 | resolve() 29 | }) 30 | }) 31 | } 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "micro-upload", 3 | "version": "1.0.1", 4 | "description": "A express-fileupload wrapper for micro", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/julianduque/micro-upload.git" 12 | }, 13 | "keywords": [ 14 | "micro", 15 | "fileupload" 16 | ], 17 | "author": "Julian Duque ", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/julianduque/micro-upload/issues" 21 | }, 22 | "homepage": "https://github.com/julianduque/micro-upload#readme", 23 | "dependencies": { 24 | "express-fileupload": "^0.1.2" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright (c) 2017 NodeSource 5 | ----------------------------- 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # micro-upload 2 | 3 | An [express-fileupload](https://npm.im/express-fileupload) wrapper for [micro](https://github.com/zeit/micro) 4 | 5 | ## Install 6 | 7 | ``` 8 | $ npm install --save micro-upload 9 | ``` 10 | 11 | ## Usage 12 | 13 | ``` js 14 | 'use strict' 15 | 16 | const { send } = require('micro') 17 | const { upload, move } = require('micro-upload') 18 | 19 | module.exports = upload(async (req, res) => { 20 | if (!req.files) { 21 | return send(res, 400, 'no file uploaded') 22 | } 23 | 24 | let file = req.files.file 25 | await move(file, `/tmp/uploads/${file.name}`) 26 | send(res, 200, 'upload success') 27 | }) 28 | ``` 29 | ## Authors and Contributors 30 | 31 | 32 | 33 |
Julián DuqueGitHub/julianduqueTwitter/@julian_duque
34 | 35 | Contributions are welcomed from anyone wanting to improve this project! 36 | 37 | ## License & Copyright 38 | 39 | **micro-upload** is Copyright (c) 2017 Julian Duque and licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included [LICENSE.md](https://github.com/julianduque/micro-upload/blob/master/LICENSE.md) file for more details. 40 | 41 | --------------------------------------------------------------------------------