Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multer does not save a file when I run it by forever.js #214

Closed
gblue1223 opened this issue Aug 24, 2015 · 5 comments
Closed

Multer does not save a file when I run it by forever.js #214

gblue1223 opened this issue Aug 24, 2015 · 5 comments

Comments

@gblue1223
Copy link

version: 1.0.3

Configuration of multer

var multer = require('multer');
var upload = multer({
    dest: './public/uploads/',
}).single('lezhinPsd');

router.post('/lezhin/upload', function(req, res){
    upload(req, res, function(err){
        if (err){
            console.log(err);
            return;
        }
        new Lezhin(req, res).upload();
  })
});

When I run my web server with below command

sudo node /home/ubuntu/www/bin/www

multer saves an upload file well to the upload directory but, when I run the server with forever.js, it doesn't.

sudo forever start /home/ubuntu/www/bin/www

I suspected 'make-middleware' so, I debugged the file but, it seems working well, 'busboy.on('finish')' function called well.

    busboy.on('finish', function () {
      console.log(222, 'readFinished');
      readFinished = true
      indicateDone()
    })

Besides, I've tried to duplicate the uploaded file to another directory, it just worked but, the file didn't show up in the upload directory.

        console.log(333, req.file.path);
//      var fs = require('fs');
//      fs.rename(req.file.path, '/home/ubuntu/www/file' + Date.now(), function(){
//          console.log(555);
//      });
        fs.createReadStream(req.file.path).pipe(fs.createWriteStream('/home/ubuntu/www/file' + Date.now()));
        console.log(444);

I even tried to find the file with 'find' command on a linux console but it was just nowhere.
What should I look at?

@gblue1223
Copy link
Author

It was path problem. When I run with forever.js

dest: './public/uploads/',

'./' means a root directory of a SYSTEM.

@fariazz
Copy link

fariazz commented Apr 12, 2016

I'm having the same problem. How did you specify the correct path for forever to understand? I tried ./ and also _dirname, but forever tries to do it on the root of the disk. If I just execute it with node it works fine.

@gblue1223
Copy link
Author

Hi Navarro,

As you’ve tried _dirname didn’t work for me as well. So I just wrote full path of the directory like '/home/gblue1223/www/upload’

Cheers,

Raphael Eom
Computer Programmer

skype: gblue1223
kakaotalk: gblue1223
email: gblue1223@gmail.com mailto:gblue1223@gmail.com
facebook: http://www.facebook.com/gblue1223 http://www.facebook.com/glue1223
p.homepage: http://gblue1223.wordpress.com http://gblue1223.wordpress.com/
c.homepage: http://www.magicnreal.com http://www.magicnreal.com/

    1. 12., 오후 4:36, Pablo Farias Navarro notifications@github.com 작성:

I'm having the same problem. How did you specify the correct path for forever to understand? I tried ./ and also _dirname, but forever tries to do it on the root of the disk. If I just execute it with node it works fine.


You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub #214 (comment)

@fariazz
Copy link

fariazz commented Apr 12, 2016

@gblue1223 thanks for your response! Ended up solving it by specifying the workingDir parameter when running forever:

forever start --workingDir <absolute path to the root of my node project> <absolute path to the script I want to run>

When doing this, both _dirname and './' work as expected.

@gblue1223
Copy link
Author

Oh, it is a better solution.

Thanks for the tip!


Raphael Eom
Computer Programmer

skype: gblue1223
kakaotalk: gblue1223
email: gblue1223@gmail.com mailto:gblue1223@gmail.com
facebook: http://www.facebook.com/gblue1223 http://www.facebook.com/glue1223
p.homepage: http://gblue1223.wordpress.com http://gblue1223.wordpress.com/
c.homepage: http://www.magicnreal.com http://www.magicnreal.com/

    1. 13., 오전 7:12, Pablo Farias Navarro notifications@github.com 작성:

@gblue1223 https://github.com/gblue1223 thanks for your response! Ended up solving it by specifying the workingDir parameter when running forever:

forever start --workingDir
When doing this, both _dirname and './' work as expected.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub #214 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants