@@ -16,15 +16,26 @@ Usage:
1616 upload = require (' jquery-file-upload-middleware' );
1717
1818 var app = express ();
19+
20+ // configure upload middleware
21+ upload .configure ({
22+ uploadDir: __dirname + ' /public/uploads' ,
23+ uploadUrl: ' /uploads' ,
24+ imageVersions: {
25+ thumbnail: {
26+ width: 80 ,
27+ height: 80
28+ }
29+ }
30+ });
31+
1932 app .configure (function () {
2033 ...
21- app .use (' /upload' , upload .fileHandler ({
22- uploadDir: __dirname + ' /public/uploads' ,
23- uploadUrl: ' /uploads'
24- }));
34+ app .use (' /upload' , upload .fileHandler ());
2535 app .use (express .bodyParser ());
2636 ...
2737 });
38+
2839```
2940
3041On the frontend:
@@ -34,13 +45,27 @@ On the frontend:
3445 <script >$ (' #fileupload' ).fileupload ({ dataType: ' json' }) </script >
3546```
3647
48+ Overriding global configuration
49+
50+ ``` javascript
51+
52+ app .use (' /upload2' , upload .fileHandler ({
53+ uploadDir: __dirname + ' /public/uploads2' ,
54+ uploadUrl: ' /uploads2' ,
55+ imageVersions: {
56+ thumbnail: {
57+ width: 100 ,
58+ height: 100
59+ }
60+ }
61+ }));
62+
63+ ```
64+
3765More sophisticated example - Events
3866
3967``` javascript
40- app .use (' /upload' , upload .fileHandler ({
41- uploadDir: __dirname + ' /public/uploads' ,
42- uploadUrl: ' /uploads'
43- }));
68+ app .use (' /upload' , upload .fileHandler ());
4469
4570 // events
4671 upload .on (' begin' , function (fileInfo ) { ... });
@@ -66,19 +91,23 @@ More sophisticated example - Events
6691Dynamic upload directory and url, isolating user files:
6792
6893``` javascript
94+ upload .configure ({
95+ imageVersions: {
96+ thumbnail: {
97+ width: 80 ,
98+ height: 80
99+ }
100+ }
101+ });
102+
69103 app .use (' /upload' , function (req , res , next ) {
104+ // imageVersions are taken from upload.configure()
70105 upload .fileHandler ({
71106 uploadDir : function () {
72107 return __dirname + ' /public/uploads/' + req .sessionID
73108 },
74109 uploadUrl : function () {
75110 return ' /uploads/' + req .sessionID
76- },
77- imageVersions: {
78- thumbnail: {
79- width: 80 ,
80- height: 80
81- }
82111 }
83112 })(req, res, next);
84113 });
@@ -94,12 +123,6 @@ Getting uploaded files mapped to their fs locations:
94123 },
95124 uploadUrl : function () {
96125 return ' /uploads/' + req .sessionID
97- },
98- imageVersions: {
99- thumbnail: {
100- width: 80 ,
101- height: 80
102- }
103126 }
104127 }, function (files ) {
105128 // {
@@ -116,6 +139,24 @@ Getting uploaded files mapped to their fs locations:
116139 });
117140```
118141
142+ Passing uploaded files down the request chain:
143+
144+ ``` javascript
145+ app .use (' /api' , function (req , res , next ) {
146+ upload .getFiles ({
147+ uploadDir : function () {
148+ return __dirname + ' /public/uploads/' + req .sessionID
149+ },
150+ uploadUrl : function () {
151+ return ' /uploads/' + req .sessionID
152+ }
153+ }, function (files ) {
154+ res .jquploadfiles = files;
155+ next ();
156+ });
157+ });
158+ ```
159+
119160Other options and their default values:
120161
121162``` javascript
@@ -144,7 +185,3 @@ Other options and their default values:
144185## License
145186Copyright (c) 2012 [ Aleksandr Guidrevitch] ( http://aguidrevitch.blogspot.com/ )
146187Released under the [ MIT license] ( http://www.opensource.org/licenses/MIT ) .
147-
148-
149-
150-
0 commit comments