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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:18:43+00:00 2026-06-02T02:18:43+00:00

I have managed to get file uploading work in Node.js with Express, and in

  • 0

I have managed to get file uploading work in Node.js with Express, and in the code i’m checking whether it’s an image or not that the user is trying to upload.

If the file was successfully uploaded I want to show a message to the user, directly to the HTML page with the uploading form. The same should be if the file the user tried to upload wasn’t an image, or something else happened during the upload.

The code below works (res.send…) but it opens up a new page containing only the message.

My question is: How can I change my code so that the message is sent directly to the HTML page instead? If it could be of any use, i’m using Jade.

Thanks in advance!

app.post('/file-upload', function(req, res, next) {
    var fileType = req.files.thumbnail.type;
    var divided = fileType.split("/");
    var theType = divided[0];

    if (theType === "image"){
        var tmp_path = req.files.thumbnail.path;

        var target_path = './public/images/' + req.files.thumbnail.name;

        fs.rename(tmp_path, target_path, function(err) {
            if (err) throw err;

            fs.unlink(tmp_path, function() {
                if (err) {
                    throw err;
                    res.send('Something happened while trying to upload, try again!');
                }
                res.send('File uploaded to: ' + target_path + ' - ' + req.files.thumbnail.size + ' bytes');
            });
        });
    }

    else {
        res.send('No image!');
    }

});
  • 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-06-02T02:18:45+00:00Added an answer on June 2, 2026 at 2:18 am

    from what I understand you are trying to send a message to an already open browser window?

    a few things you can do,

    1. Ajax it, send the post, and process the return info.
    2. Submit it as you are doing now, but set a flash message (look at http://github.com/visionmedia/express-messages) and either res.render the form page, or res.redirect to the form function
    3. now.js or a similar solution. This would let clientside use serverside functions and serverside code to run clientside functions. So what you would do would be on submit, pass the post values to a serverside function, which will process it and trigger a clientside function (display a message)

    For my money option #2 is probably the safest bet, as clients without javascript enabled will be able to use it. As for usability #1 or #3 would give a more streamlined appearance to the end user.

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

Sidebar

Related Questions

So far I have managed to get the background image to stretch: XHTML: <div
Have you managed to get Aptana Studio debugging to work? I tried following this,
Has anyone managed to get this to work? Closest I have found is a
I have managed to get my first python script to work which downloads a
I have managed to get a cron job to run a rake task by
Ok so I have managed to get the format of the date presented in
I am learning basics of EJB 3.0. I have managed to get a sample
I'm writing a MVC website and using jqGrid. I have managed to get it
I have successfully managed to get System.Speech.Synthesis to read English text in arbitrary voices
I have finally managed to get javan-whenever gem working on my site5 server, and

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.