Search code examples
node.jsexpressubuntu-14.04upstartmulter

node js multer file upload not working when started with ubuntu upstart


I have a VPS(ubuntu 14.04) and a nodejs app with multer for handler file upload and it works find when I start the server via node ex."node my-server.js"

but not if I start via upstart ex."sudo start node-app" node-app is a ubuntu upstart conf file here is the code

multer I use with express here is the code. my-server.js

app.use(multer({
  dest: './public/images/',
  rename: function(fieldname, filename) {
    return filename;
  }
}));

my upstart file: /etc/init/node-app.conf

description "node.js server"
author      "Name"

start on (local-filesystems and net-device-up IFACE=wlan0)

stop on shutdown

# Automatically Respawn:
respawn
respawn limit 99 5

script
    export HOME="/home/username/www/site-server/"
    exec node $HOME/bin/www 13002 >> /var/log/node.log 2>&1
end script

on my node.log I have this.

{ [Error: Command failed: identify.im6: unable to open image `/home/username/www/my-node-app/public/images/hqdefault.jpg': No such file or directory @ error/blob.c/OpenBlob/2638.
] timedOut: false, killed: false, code: 1, signal: null }

any idea why is not working via upstart?


Solution

  • It needs to be able to write uploaded files to disk, so it probably doesn't have permission to write to the destination directory.

    Ensure that upstart runs it from user account that has access to upload directory you've configured in multer.