My code is like this:
app.configure(function () {
app.use(express.static(__dirname + "/media"));
app.use(express.bodyParser({
keepExtensions: true
}));
})
app.post('/upload', function (req, res) {
console.log(req.files);
res.send("well done");
return;
})
ant do some job like:
1.Do someting on the progoress
event, how can I bind handler to the progress
, complete
event, I have tried req.files.on('progress', fn)
, but it doesn't work
2
I know how to use req.files
to get the file's imformation,
but how can I limit the upload file's size before it upload, or limit the upload image resolution?
You should look at multipart middleware documentation, this is the one involved in file uploading.
It says that the limit is set via the "limit" option and that progress could be listened to if you put "defer" option to true. In that case the form used by the upload is set as an attribute of your request. Then you will be able to listen to the progress event.
So your code should look like this (not tested yet):
I have a function in my project that loads files, might help you a bit: