https://github.com/dckt/basic-upload
Simple file upload for express
https://github.com/dckt/basic-upload
Last synced: about 1 year ago
JSON representation
Simple file upload for express
- Host: GitHub
- URL: https://github.com/dckt/basic-upload
- Owner: DCKT
- License: mit
- Created: 2016-01-10T13:39:49.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-01-10T21:36:12.000Z (over 10 years ago)
- Last Synced: 2025-02-11T13:28:29.220Z (over 1 year ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Basic upload
Upload file easly, that's it !
## Requirement
You need to use the latest stable version of Node.js (4.2 or higher)
## How it works
The module deserve an **upload** function which use `Promise`.
The files are stored in the directory **uploads** at the top of your application.
## Example
```js
const upload = require('basic-upload');
// /uploads deserve static files
app.use(express.static(path.join(__dirname, '../uploads')));
// assuming an express app
// don't forget to enable multipart/form-data
app.post('/pictures/new', function(req, res) {
const product = req.body.pictures;
upload({
file: req.files.picture, // unique file
files: req.files.gallery, // array of file
parentDirectory: 'pictures',
dirname: product.ref
})
.then(filesUploaded => {
Picture.create({
path: filesUploaded[0].path,
name: filesUploaded[0].fileName,
})
.then(() => {
res.redirect('/');
});
})
.catch(err => {
console.error(err);
})
});
```
## API
**function upload(params)**
params is an object who can hold :
- file: unique file
- files: array of files
- parentDirectory: name of the parent directory
- dirname : name of the directory where the files will be uploaded
The function resolve a filesUploaded variable which is an array of object who contain the filename and the path for each file.