Created
January 26, 2012 11:57
-
-
Save chrismcv/1682443 to your computer and use it in GitHub Desktop.
Gzip upload with formidable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var receivedFile, form = new formidable.IncomingForm(); | |
form.keepExtensions = true; | |
form.on('file', function (field, file) { | |
receivedFile = file; | |
}).on('end', function () { | |
var inp = fs.createReadStream(receivedFile.path); | |
var out = fs.createWriteStream(receivedFile.filename); | |
inp.pipe(gzip).pipe(out); | |
fs.unlink(receivedFile.path, function (err) { | |
if (err) console.log(err); | |
else { | |
response.end('received files:\n\n ' + receivedFile); | |
} | |
}); | |
}); | |
form.parse(request); | |
} else next(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment