diff --git a/.gitignore b/.gitignore index 40b878d..0ca9404 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,25 @@ -node_modules/ \ No newline at end of file +### intellij ### +*.iml +*.ipr +*.iws +.idea/ + +### node ### +lib-cov +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz + +pids +logs +results + +npm-debug.log +node_modules + +### example ### +public/lib/ \ No newline at end of file diff --git a/History.md b/History.md index b47f606..8a03709 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,49 @@ +0.1.7 / 2014-10-09 +================== + + * #58 improved support for IE9 + +0.1.6 / 2014-10-04 +================== + + * #56 avoid path traversal in DELETE requests + +0.1.5 / 2014-08-02 +================== + + * #31 request and response objects passed to event handlers + +0.1.4 / 2014-07-06 +================== + + * #53 documentation update + +0.1.3 / 2014-07-05 +================== + + * #46 merged in (reduce synchronous disk IO operations) + +0.1.2 / 2014-06-08 +================== + + * #31 merged in + +0.1.1 / 2014-02-04 +================== + + * #5 fixed + +0.1.0 / 2013-10-07 +================== + + * documentation cleanup + + +0.0.9 / 2013-10-07 +================== + + * compatibility with jQuery File Upload Plugin 5.32.6 + 0.0.8 / 2013-01-01 ================== diff --git a/README.md b/README.md index 0aaac0a..204c7a3 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,38 @@ On the frontend: ``` +To prevent access to /upload except for post (for security) +```javascript +upload.configure({ + uploadDir: __dirname + '/public/uploads/', + uploadUrl: '/uploads' +}); + +/// Redirect all to home except post +app.get('/upload', function( req, res ){ + res.redirect('/'); +}); + +app.put('/upload', function( req, res ){ + res.redirect('/'); +}); + +app.delete('/upload', function( req, res ){ + res.redirect('/'); +}); + +app.use('/upload', function(req, res, next){ + upload.fileHandler({ + uploadDir: function () { + return __dirname + '/public/uploads/' + }, + uploadUrl: function () { + return '/uploads' + } + })(req, res, next); +}); +``` + Overriding global configuration ```javascript @@ -68,7 +100,7 @@ More sophisticated example - Events app.use('/upload', upload.fileHandler()); // events - upload.on('begin', function (fileInfo) { + upload.on('begin', function (fileInfo, req, res) { // fileInfo structure is the same as returned to browser // { // name: '3 (3).jpg', @@ -81,10 +113,10 @@ More sophisticated example - Events // thumbnail_url: 'http://youhost/uploads/thumbnail/3%20(3).jpg' // } }); - upload.on('abort', function (fileInfo) { ... }); - upload.on('end', function (fileInfo) { ... }); - upload.on('delete', function (fileInfo) { ... }); - upload.on('error', function (e) { + upload.on('abort', function (fileInfo, req, res) { ... }); + upload.on('end', function (fileInfo, req, res) { ... }); + upload.on('delete', function (fileInfo, req, res) { ... }); + upload.on('error', function (e, req, res) { console.log(e.message); }); ``` @@ -245,6 +277,10 @@ Other options and their default values: ## Contributors * [@soomtong](http://github.com/soomtong) + * [@gsarwohadi](https://github.com/gsarwohadi) + * [@peecky](https://github.com/peecky) + * [@tonyspiro](https://github.com/tonyspiro) + * [@derjust](https://github.com/derjust) ## License Copyright (c) 2012 [Aleksandr Guidrevitch](http://aguidrevitch.blogspot.com/) diff --git a/examples/.bowerrc b/examples/.bowerrc new file mode 100644 index 0000000..0f29f6a --- /dev/null +++ b/examples/.bowerrc @@ -0,0 +1,4 @@ +{ + "directory": "public/lib", + "json": "bower.json" +} \ No newline at end of file diff --git a/examples/README.md b/examples/README.md index 3f8c0d8..32c2010 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,9 +1,14 @@ ## YET ANOTHER JQUERY FILE UPLOAD MIDDLEWARE EXAMPLES +- use bower to install jquery-file-upload script (tested version 8.8.5) + to run ``` +project > npm insatll +project > cd examples project/examples > npm insatll +project/examples > bower insatll project/examples > node app.js ``` diff --git a/examples/app.js b/examples/app.js index 4667fcd..429526d 100644 --- a/examples/app.js +++ b/examples/app.js @@ -8,11 +8,9 @@ * */ var express = require('express'), http = require('http'), - //upload = require('../index'); - upload = require('jquery-file-upload-middleware'); // don't work 0.0.8 && update > 0.0.8 + upload = require('../'); -var cons = require('consolidate'), - swig = require('swig'); +var swig = require('swig'); // configuration @@ -26,15 +24,12 @@ var app = express(); // set template engine -app.engine('html', cons.swig); -swig.init({ - root: __dirname + '/views', - allowErrors: true, - cache: false +app.engine('html', swig.renderFile); +swig.setDefaults({ + cache: false // default 'memory' }); - // jquery-file-upload helper app.use('/upload/default', function (req, res, next) { upload.fileHandler({ @@ -74,6 +69,7 @@ upload.on('end', function (fileInfo) { upload.on('delete', function (fileName) { // remove file info + console.log("files remove complete"); console.log(fileName); }); @@ -114,7 +110,11 @@ app.configure('production', function () { * routes * */ app.get('/', function (req, res) { - res.send('Call this url in browser : http://localhost:3001/location/input'); + var html = [ + '
Call this url in browser : http://localhost:3001/location/input Go
', + 'Call this url in browser : http://localhost:3001/upload/location/list Go
' + ].join(''); + res.send(html); }); @@ -140,4 +140,5 @@ app.post('/location/input', function (req, res) { http.createServer(app).listen(app.get('port'), function () { console.log("Express server listening on port " + app.get('port')); console.log("access url /location/input"); + console.log("access url /upload/location/list"); }); diff --git a/examples/bower.json b/examples/bower.json new file mode 100644 index 0000000..1c7639f --- /dev/null +++ b/examples/bower.json @@ -0,0 +1,13 @@ +{ + "name": "jquery-file-upload-middleware", + "version": "0.0.1", + "ignore": [ + ".jshintrc", + "**/*.txt" + ], + "dependencies": { + "jquery-file-upload": "8.8.5" + }, + "devDependencies": { + } +} \ No newline at end of file diff --git a/examples/config.js b/examples/config.js index 129c04e..b4138cc 100644 --- a/examples/config.js +++ b/examples/config.js @@ -46,7 +46,7 @@ exports.resizeVersion = { }; exports.directors = { - temp: './public/tmp', + temp: './tmp', default: '/public/uploads/default', default_url: '/uploads/default', diff --git a/examples/package.json b/examples/package.json index d65805b..c435dee 100644 --- a/examples/package.json +++ b/examples/package.json @@ -2,9 +2,7 @@ "name":"examples", "version":"0.0.1", "dependencies":{ - "express":">= 3.0.0", - "consolidate":">= 0.4.0", - "swig":">= 0.12.0", - "jquery-file-upload-middleware": "> 0.0.8" + "express":"3.3.x", + "swig":"1.0.x" } } \ No newline at end of file diff --git a/examples/public/scripts/file_upload.js b/examples/public/scripts/file_upload.js index ea8d49d..603c48f 100644 --- a/examples/public/scripts/file_upload.js +++ b/examples/public/scripts/file_upload.js @@ -66,13 +66,13 @@ $('#location_gallery').fileupload({ row.find('.name a').text(file.name); if (file.url) { row.find('.preview').append('