question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multer does not save anything to me

See original GitHub issue

Hello,

here is my code I’m using on server side::

var uploader = multer({
    dest: 'upload/',
    filename: function (req, file, cb) {
        console.log('>>>>>>>>>>>>>>>>>>>', file);
        cb( null, file.fieldname + '-' + Date.now() );
    }
});
var uploadHandler = function(req, res, next){
    if( req.url !== '/system/upload' || req.method !== 'POST') return next();

    uploader.array('x-files')( req, res, function( err ){
        console.log('???????????????', err, req.files, req.file);
    } );
};
...
.use( uploadHandler )

On client side vanilla javascript:

upload: function( url, files ){
    var self = this;

    var formData = new FormData();
    formData.append( 'x-files', Array.isArray(files)?files:[files] );

    var request = new XMLHttpRequest();
    request.open('POST', url, true);

    request.send( formData );
}

The line

console.log('???????????????', err, req.files, req.file); 

works, I see ‘???’ on the screen but err, req.files, req.file are all undefined and the filename function is never called and nothing is stored in the folder upload

No error, yet no files are stored or set in the req object…

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
LinusUcommented, Oct 23, 2015

This issue have now been dormant for >1 month, please answer the last instructions I posted to get more help 😃

0reactions
LinusUcommented, Sep 19, 2015

Could you try the following code:

var upload = multer({ dest: 'upload/' }).array('x-files')

function uploadHandler (req, res, next) {
  if (req.url !== '/system/upload' || req.method !== 'POST') return next()

  console.log('STARTING UPLOAD')

  upload(req, res, function (err) {
    if (err) return next(err)

    console.log('UPLOAD FINISHED')
    console.log(req.files)
  })
}

app.use(uploadHandler)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Multer is grabbing images but it is not saving my files in the ...
I setup multer but for some reason it is not saving any of the photos that I want it to save locally so...
Read more >
Express multer middleware
Multer is a node.js middleware for handling multipart/form-data , which is primarily used for uploading files. It is written on top of busboy...
Read more >
File uploads using Node.js - CodeForGeek
Nice tutorial, but I'm trying to follow your steps and I'm not able to upload files. When I click the Upload button, the...
Read more >
Multer Does Not Save File In The Folder - ADocLib
In this tutorial we are going to learn how to upload files on the server with Multer will not process any form which...
Read more >
Upload Files from Multiple Fields using Multer | by Aakash Jha
When I started making the page to upload audiobooks — for the admin, i.e. me, I faced a challenge getting files from multiple...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found