Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda