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 6876691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:30:33+00:00 2026-05-27T04:30:33+00:00

I am trying to make a Node.js file uploader with a AJAX progress bar.

  • 0

I am trying to make a Node.js file uploader with a AJAX progress bar.

var formidable = require('./formidable'), http = require('http'), sys = require('sys');
 http.createServer(function(req, res) {
  if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
    // parse a file upload
    var form = new formidable.IncomingForm();
    form.uploadDir = './node_uploads';
    form.keepExtensions = true;
    //print the upload status in bytes
    form.addListener("progress", function(bytesReceived, bytesExpected) {
        //progress as percentage
        progress = (bytesReceived / bytesExpected * 100).toFixed(2);
        mb = (bytesExpected / 1024 / 1024).toFixed(1);
        sys.print("Uploading "+mb+"mb ("+progress+"%)\015");
    });
    //enter here after upload complete
    form.parse(req, function(fields, files) {
        sys.debug("Upload Complete");
        res.writeHead(200, {'content-type': 'text/plain'});
        res.write('received upload:\n\n');
        res.end());
    });
    return;
  }
  if (req.url == '/update') {
        res.writeHead(200, {'content-type': 'text/plain'});
        res.write('<?xml version="1.0"?><response><status>1</status><message>'+ 000 +'</message> </response>');
        res.end();

    }
  // show a file upload form
  res.writeHead(200, {'content-type': 'text/html'});
  res.end
    ( '<form action="/upload" enctype="multipart/form-data" method="post">'
    + '<p id="statuslabel"></p><p id="anotherlabel"></p>' 
    + '<input type="text" name="title" id="title"><br>'
    + '<input type="file" name="upload" multiple="multiple"><br>'
    + '<input type="submit" value="Upload" id="uploadform">'
    + '</form>'
    );
}).listen(8000, '127.0.0.1');

The jQuery is quite lengthy so I have cut it out but all it does is start a timer and request data from update and set on the label.

With this code will node accept multiple uploads from different hosts ?
Also Firefox doesnt seem to work but Safari/Chrome does any idea ?
How would I request a status for the file upload ?

Thanks, Alex

  • 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-27T04:30:33+00:00Added an answer on May 27, 2026 at 4:30 am

    One thing you’ll need is a way to identify a particular upload uniquely. The form should include a unique ID as a hidden field that identifies the upload. Then when doing the upload you can keep a map of ID -> progress level and the “update” call would pass that ID to make sure it is looking at the right progress indicator.

    What you may find, however, is that browsers only allow a limited number of connections to the server. So, your request for a progress update might wait for the actual upload to finish before it even gets sent to the server.

    To get around it you might need to use socket.io to open a connection to the server that stays open before initiating the upload, and receive updates on that connection as the upload progresses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to make a page which will recursively call a function until a limit
Im trying to make a function that will return an element of type point:
I'm trying to make a simple custom field field_book_year for the new node type
I'm trying to make the node-mongodb-native driver from git, but when i try and
I'm trying to pull a gzipped json file from http://api.discogs.com/release/339901 . I have https://github.com/waveto/node-compress
I`m trying to make a small game on node.js + socket.io + mysql. The
I wrote a file tree using JTree, and now I am trying to make
I'm trying to make a Jstree, the code for it is the following: $(function
Just trying to make a kind of hash table with each node being a
I am trying make long screen to vertical direction. So, I need a screen

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.