Receive file uploads
Mark the route with @upload so it only accepts multipart/form-data, and set a size limit that fits the files you expect (here <5mb). The uploaded files are in $.files; the other fields of the form are in $.body. Each file has name, filename, size and type, and methods such as read(), copy() and move().
exports.install = function() {
ROUTE('POST /upload/ @upload <5mb', upload);
};
function upload($) {
var file = $.files[0];
if (!file) {
$.invalid('No file');
return;
}
file.read(function(err, buffer) {
$.json({
filename: file.filename,
size: file.size,
type: file.type,
text: buffer.toString('utf8'),
title: $.body.title
});
});
}