Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion express and formidable and restful server and sending a file from a REST client
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Gustavo Machado  
View profile  
 More options Oct 3 2012, 4:34 pm
From: Gustavo Machado <machad...@gmail.com>
Date: Wed, 3 Oct 2012 17:34:04 -0300
Local: Wed, Oct 3 2012 4:34 pm
Subject: Re: [nodejs] express and formidable and restful server and sending a file from a REST client

Maybe this can help. When trying to use ajax uploader and also plain forms,
I found that I had to do something like this it's coffeescript):

        if req.xhr
            req.tempFile = path.join(tmp.tmpdir, req.header("x-file-name"))
            writer = fs.createWriteStream(req.tempFile)
            req.pipe writer
            writer.on "close", () ->
                next()
        else
            req.tempFile = req.files[Object.keys(req.files)[0]]
            next()

Hope it helps!
Gus

On Wed, Oct 3, 2012 at 1:09 PM, BlondAngelNYC <pauled...@gmail.com> wrote:
> 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:

> http://steelballsafety.wordpress.com/2012/01/25/express-rawbody/
> 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 nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.