Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6093037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:30:50+00:00 2026-05-23T12:30:50+00:00

Ok so ive already tried using connect-form and I couldnt get it working for

  • 0

Ok so ive already tried using connect-form and I couldnt get it working for some reason, but I figure I should understand how this works semi from scratch regardless.

I dont understand where the multipart/formdata file which I am uploaded is going, or how I can access it in my app when its posted to the url. — Id like to access the file data directy, and write the file output using the node fs module. — For instance:

    app.post('/testy', function(req, res){
       console.log(req.body);
       console.log(req.headers);
       res.redirect('back');

    });  

    app.get('/testy', function(req, res){
      res.send('<form method="post" action="/testy" enctype="multipart/form-data">'
        + '<p>Image: <input type="file" name="test" /></p>'
        + '<p><input type="submit" value="Upload" /></p>'
        + '</form>');
    });

So the only req var that is actually being logged there is the req headers, body is empty. (probably supposed to be I understand that). But what I dont get is where is the file data? Looking for the php equiv of the $_FILES array I supposed. — Here is my headers logged.

'accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'accept-language': 'en-us,en;q=0.5',
'accept-encoding': 'gzip,deflate',
'accept-charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'keep-alive': '115',
connection: 'keep-alive',
referer: 'http://127.0.0.1:3000/testy',
cookie: 'connect.sid=lDRpluTxjUJeuTmkXlybrYeZ.JYTB155s2DGce2dsyfv1Op5ISCY8uqyqJZK8NjlZ5jM; socketio=flashsocket',
'x-insight': 'activate',
'content-type': 'multipart/form-data; boundary=---------------------------5856401949371863571646035001',
'content-length': '30128' }

Any light shed upon what Im missing as always much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:30:51+00:00Added an answer on May 23, 2026 at 12:30 pm

    Here is very verbose version without connect-form. As you can see, this is not efficient but trying to be instructive about how it works.

    var express = require('express'),
        fs = require('fs');
        app = express.createServer();
    
    app.post('/testy', function(req, res){
      var body = '';
      var header = '';
      var content_type = req.headers['content-type'];
      var boundary = content_type.split('; ')[1].split('=')[1];
      var content_length = parseInt(req.headers['content-length']);
      var headerFlag = true;
      var filename = 'dummy.bin';
      var filenameRegexp = /filename="(.*)"/m;
      console.log('content-type: ' + content_type);
      console.log('boundary: ' + boundary);
      console.log('content-length: ' + content_length);
    
      req.on('data', function(raw) {
        console.log('received data length: ' + raw.length);
        var i = 0;
        while (i < raw.length)
          if (headerFlag) {
            var chars = raw.slice(i, i+4).toString();
            if (chars === '\r\n\r\n') {
              headerFlag = false;
              header = raw.slice(0, i+4).toString();
              console.log('header length: ' + header.length);
              console.log('header: ');
              console.log(header);
              i = i + 4;
              // get the filename
              var result = filenameRegexp.exec(header);
              if (result[1]) {
                filename = result[1];
              }
              console.log('filename: ' + filename);
              console.log('header done');
            }
            else {
              i += 1;
            }
          }
          else { 
            // parsing body including footer
            body += raw.toString('binary', i, raw.length);
            i = raw.length;
            console.log('actual file size: ' + body.length);
          }
      });
    
      req.on('end', function() {
        // removing footer '\r\n'--boundary--\r\n' = (boundary.length + 8)
        body = body.slice(0, body.length - (boundary.length + 8))
        console.log('final file size: ' + body.length);
        fs.writeFileSync('files/' + filename, body, 'binary');
        console.log('done');
        res.redirect('back');
      })
    });  
    
    app.get('/testy', function(req, res){
      res.send('<form method="post" action="/testy" enctype="multipart/form-data">'
               + '<p>Image: <input type="file" name="test" /></p>'
               + '<p><input type="submit" value="Upload" /></p>'
               + '</form>');
    });
    
    app.listen(4000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tried many functions already, but I simply can't figure this out. The right
I've already tried using many different techniques with this... One that works pretty nicely
http://github.com/gabriel/yajl-objc I've already tried SBJSON, and while it works, I'm looking into alternative options
When I run this code the selected item is not visible. I've already tried
I've tried several things already, std::stringstream m; m.empty(); m.clear(); both of which don't work.
I've already referred to this SO post . I've been embedding images using an
I've already got my custom header drawing in my GridView using SetRenderMethodDelegate on the
I've already found the following question , but I was wondering if there was
I've already implemented, using macros, a C++ property system that satisfied the following requirements:
I have an application that originally needed to connect to Sybase (via ODBC), but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.