I have busboy in my ExpressJS app for file streaming. Now at some point I wish to send back a regular response that the file size is too large. How can I do that?
Here is my code to illustrate what I want:
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype);
let fileSize = 0;
file.on('data', function(data) {
fileSize += data.length;
console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
});
file.on('end', function() {
console.log('File [' + fieldname + '] Finished');
if (fileSize > MAXIMUM_ALLOWED_FILE_UPLOAD_SIZE) {
//I wish to send back a regular response that the file size is too large here.
}
fileSize = 0;
});
});
busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
console.log('Field [' + fieldname + ']: value: ' + inspect(val));
});
How can I achieve that?