|
1 | 1 | # express-fileupload
|
2 | 2 | Simple express middleware for uploading files.
|
3 | 3 |
|
4 |
| -[](https://www.npmjs.org/package/express-fileupload) |
| 4 | +[](https://www.npmjs.org/package/express-fileupload) |
5 | 5 | [](https://travis-ci.org/richardgirges/express-fileupload)
|
6 | 6 | [](https://www.npmjs.org/package/express-fileupload)
|
7 | 7 | [](https://coveralls.io/r/richardgirges/express-fileupload)
|
8 | 8 |
|
9 |
| -# Version 0.1.0 Breaking Changes |
| 9 | +# Version 0.1.0 Breaking Changes! |
10 | 10 |
|
11 |
| -### BREAKING CHANGE #1: No more urlencoded support |
| 11 | +#### » No more urlencoded support |
12 | 12 | As of `v0.1.0`, there is NO MORE `application/x-www-form-urlencoded` SUPPORT! Moving forward, express-fileupload is considered a "multipart" solution only.
|
13 | 13 |
|
14 | 14 | If you want to parse `urlencoded` requests, [use body-parser](https://github.com/expressjs/body-parser#bodyparserurlencodedoptions).
|
15 | 15 |
|
16 |
| -### BREAKING CHANGE #2: Support for Node v4.x.x and above |
| 16 | +#### » Support for Node v4.x.x and above |
17 | 17 | No more support for Node 0.8+. Use with lower versions of Node at your own risk!
|
18 | 18 |
|
19 | 19 | # Install
|
@@ -46,32 +46,26 @@ The **req.files.foo** object will contain the following:
|
46 | 46 | ### Full Example
|
47 | 47 | **Your node.js code:**
|
48 | 48 | ```javascript
|
49 |
| -var express = require('express'); |
50 |
| -var fileUpload = require('express-fileupload'); |
51 |
| -var app = express(); |
| 49 | +const express = require('express'); |
| 50 | +const fileUpload = require('express-fileupload'); |
| 51 | +const app = express(); |
52 | 52 |
|
53 | 53 | // default options
|
54 | 54 | app.use(fileUpload());
|
55 | 55 |
|
56 | 56 | app.post('/upload', function(req, res) {
|
57 |
| - var sampleFile; |
58 |
| - |
59 |
| - if (!req.files) { |
60 |
| - res.send('No files were uploaded.'); |
61 |
| - return; |
62 |
| - } |
| 57 | + if (!req.files) |
| 58 | + return res.status(400).send('No files were uploaded.'); |
63 | 59 |
|
64 | 60 | // The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
|
65 |
| - sampleFile = req.files.sampleFile; |
| 61 | + let sampleFile = req.files.sampleFile; |
66 | 62 |
|
67 | 63 | // Use the mv() method to place the file somewhere on your server
|
68 | 64 | sampleFile.mv('/somewhere/on/your/server/filename.jpg', function(err) {
|
69 |
| - if (err) { |
70 |
| - res.status(500).send(err); |
71 |
| - } |
72 |
| - else { |
73 |
| - res.send('File uploaded!'); |
74 |
| - } |
| 65 | + if (err) |
| 66 | + return res.status(500).send(err); |
| 67 | + |
| 68 | + res.send('File uploaded!'); |
75 | 69 | });
|
76 | 70 | });
|
77 | 71 | ```
|
|
0 commit comments