Created
September 10, 2010 13:11
-
-
Save proppy/573596 to your computer and use it in GitHub Desktop.
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
proppy@unubore:~/Desktop/mape$ cat connectform.js | |
var connect = require('connect'); | |
var form = require('connect-form'); | |
var server = connect.createServer( | |
form({ keepExtensions: true }), | |
function(req, res, next){ | |
// Form was submitted | |
if (req.form) { | |
// Do something when parsing is finished | |
// and respond, or respond immediately | |
// and work with the files. | |
req.form.complete(function(err, fields, files){ | |
res.writeHead(200, {}); | |
if (err) res.write(JSON.stringify(err.message)); | |
res.write(JSON.stringify(fields)); | |
res.write(JSON.stringify(files)); | |
res.end(); | |
}); | |
// Regular request, pass to next middleware | |
} else { | |
next(); | |
} | |
} | |
); | |
server.listen(8000);proppy@unubore:~/Desktop/mape$ node connectform.js & | |
[1] 11408 | |
proppy@unubore:~/Desktop/mape$ curl -F 'field=@/home/proppy/Pictures/kiwi.png' http://localhost:8000 | |
{}{"field":{"path":"/tmp/ad21f1831323cd74e2fbfd2b66a05b87.png","filename":"kiwi.png","mime":"application/octet-stream"}}proppy@unubore:~/Desktop/mape$ gnome-open /tmp/ad21f1831323cd74e2fbfd2b66a05b87.png | |
proppy@unubore:~/Desktop/mape$ file /tmp/ad21f1831323cd74e2fbfd2b66a05b87.png | |
/tmp/ad21f1831323cd74e2fbfd2b66a05b87.png: PNG image, 600 x 600, 8-bit/color RGBA, non-interlaced |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment