I built a restful server based on express (and express relies on formidable). I used this form to perform my test:
<form action="/docxv" method="post" enctype="multipart/form-data">
<input type="submit" value="Upload">
<input type="file" name="uploadfile">
</form>
However customer wants the REST client to send the file to the restful server *WITHOUT* using multipart/form-data. So I changed the form to be this:
<form action="/docxv" method="post">
<input type="submit" value="Upload">
<input type="file" name="uploadfile">
</form>
That way, the form is sent as UUEncoded instead of multipart.
My restful server javascript code (I am listing only the important bits):
var app = express();
app.configure(function () {
app.use(express.bodyParser({keepExtensions: true, hash:'md5' }));
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(application_root, "public")));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
//router POST /docxv (upload a file and generate a new ID)
app.post(uploadform, function (req, res){
uploadfileMultipart(req, res, 0);
});
//start the server.
app.listen(port);
logger.info('Server running on port ' + port);
//from POST router
function uploadfileMultipart(req, res, id) {
var keys = Object.keys(req.files);
var currentFile = req.files[keys[0]];
var data = fs.readFileSync(currentFile.path,, 'base64');
//...etc...
}
The problem is -- when changing from multipart to non-multipart, the req.files parameter no longers works correctly. So, I was thinking that I should try to get the raw data from request but I don't have an easy way to do that... However I found tantalizing tidbits but no solid examples. One such tidbit:
So I added that to my code like this within the app.configure snippet:
app.configure(function () {
app.use(function(req, res, next) {
var data='';
req.setEncoding('utf8');
req.on('data', function(chunk) {
data += chunk;
});
req.on('end', function() {
req.rawBody=data;
next();
});
});
app.use(app.router);
app.use(express.static(path.join(application_root, "public")));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
Unfortunately, when running this, either it hangs (when using UUEncode) or that req.rawBody is undefined (when using multipart). I am a noob, and I *did* search but not much luck. I know about the incoming.onForm function, but there are no solid examples for me to follow while using ExpressJS (which in turn uses Formidable).
Any help would be appreciated.
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en