Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Node File upload issue

I am constantly getting the printed out message of "No File Upload" Failed when I select my image and hit upload. It never goes to true..

As you can see, I am not actually uploading here. Just testing the req.files is there something wrong in my router.post? Any input would be appreciated.

router.post('/upload', async (req, res) => {

 
  try {
        if(!req.files) {
            res.send({
                status: false,
                message: 'No file uploaded'
            });
        } else {
            res.send({
                status: true,
                message: 'Files are uploaded',
                data: data
            });
        }
    } catch (err) {
        res.status(500).send(err);
    }


})
module.exports=router

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

can you share your controller file of it and also you are using async function but not defining await inside of that function,must have to use 'await' when executing async function.

about 4 years ago · Juan Pablo Isaza Report

0

here is the controller file AAmir

let fs = require('fs');
let async = require('async');

function uploaddownFiles(connection, fromFolder, toFolder, sftpmethod) {
    return new Promise((resolve, reject) => {
        // Getting all file list in given folder of local machine
        let fileList = fs.readdirSync(fromFolder);
        // filter only files not folders
        fileList = fileList.filter(file => {
            if (file.includes('.')) return true;
            return false;
        });
        console.log('Total files: ', fileList.length)
        if (!fileList.length) return reject('No file to send')
        connection.sftp(function (err, sftp) {
            if (err) return;
            async.eachOfSeries(fileList, (file, key, cb) => {
                let moveFrom = `${fromFolder}/${file}`;
                let moveTo = `${toFolder}/${file}`;
                if (sftpmethod=== 'put')
                    sftp.fastPut(moveFrom, moveTo, {}, function (uploadError) {
                        if (uploadError) return cb(uploadError);
                        console.log("Successfully Uploaded", file);
                        cb();
                    });
                else if (sftpmethod === 'get')
                    sftp.fastGet(moveFrom, moveTo, {}, function (uploadError) {
                        if (uploadError) return cb(uploadError);
                        console.log("Successfully Downloaded", file);
                        cb();
                    });
            }, function (err) {
                if (err) {
                    console.log(err);
                    return reject(err);
                } else {
                    console.log('all files have been uploaded/downloaded');
                    return resolve();
                }
            })
        });
    });
}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!