Skip to content

Commit

Permalink
docs: express backed example
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuri committed Sep 2, 2016
1 parent d763019 commit 28d94e2
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ npm install ng2-uploader
#### Backend Examples

1. [NodeJS using HapiJS](https://github.com/jkuri/ng2-uploader#backend-example-using-hapijs)
2. [PHP (Plain)](https://github.com/jkuri/ng2-uploader#backend-example-using-plain-php)
2. [NodeJS using express](https://github.com/jkuri/ng2-uploader#backend-example-using-express)
3. [PHP (Plain)](https://github.com/jkuri/ng2-uploader#backend-example-using-plain-php)

### Basic Example

Expand Down Expand Up @@ -396,6 +397,42 @@ server.start(() => {
});
````

### Backed example using express

````js
const express = require('express');
const cors = require('cors');
const multer = require('multer');
const path = require('path');

const app = express();
app.use(cors());

const upload = multer({
dest: 'uploads/',
storage: multer.diskStorage({
filename: (req, file, cb) => {
let ext = path.extname(file.originalname);
cb(null, `${Math.random().toString(36).substring(7)}${ext}`);
}
})
});

app.post('/upload', upload.any(), (req, res) => {
res.json(req.files.map(file => {
let ext = path.extname(file.originalname);
return {
originalName: file.originalname,
filename: file.filename
}
}));
});

app.listen(10050, () => {
console.log('ng2-uploader server running on port 10050.');
});
````

### Backend example using plain PHP

````php
Expand Down

0 comments on commit 28d94e2

Please sign in to comment.