1

Hiya all thanks in advance for any help you can provide. I am using C9.io, node, express, multer, gridfs-stream. And Im getting:

 /home/ubuntu/workspace/node_modules/multer/index.js:25
  mkdirp(dest, function(err) { if (err) throw err; });
 Error: EACCES, mkdir '/uploads'

I run the server.js script and that is the error that I get. I believe is something to do with permissions but i have tried chown the public folder and chmod ax, you guys have any other suggestions as to what to do?. Still get same error. The code I have is server.js

app.use('/uploads', express.static(__dirname + '/public/uploads'));
app.use(multer({dest: '/uploads/'}));

app.use(methodOverride());

app.get('/form',function (req,res){
   res.render('form'); 
});

app.get('/api/taxis', function(req,res){
    taxiModel.Taxi.find({}).exec(function(error,collection){
        res.send(collection);
        });
});

// app.get('user/:name', function(req,res){
//     taxiModel.Taxi.find({name:req.param.nmae},function(err,docs){
//       if(err)res.json(err);
//       else res.render();
//     }
// });

app.get('*', function (req,res){
   res.render('index'); 
});
app.post('/new',function(req,res){
    var dirname = require('path').dirname(__dirname);
     var filename = req.files.dnimgfront.name;
     var path = req.files.dnimgfront.path;
     var type = req.files.dnimgfront.mimetype;
     var gfs = Grid(conn.db);
     var read_stream =  fs.createReadStream(dirname + '/' + path);
     var writestream = gfs.createWriteStream({filename: filename});
     read_stream.pipe(writestream);

});




mongoose.connect('mongodb://jsrosas:12345@ds031721.mongolab.com:31721/taxis');

var conn=mongoose.connection;

conn.once('open', function(){
    console.log('connected to mongodb succesfully!');
});

app.listen(process.env.PORT, process.env.IP);
jsrosas
  • 103
  • 2
  • 14
  • I'm pretty sure you don't actually want to write to '/uploads' in the first place. Try `app.use(multer({dest: './uploads/'}));` – generalhenry Jan 15 '15 at 21:55
  • Or better yet: `app.use(multer({dest: __dirname + '/public/uploads/'}));` since it seems you are serving that directly already, or if you really meant: `app.use(multer({dest: __dirname + '/uploads'}));` – mscdex Jan 15 '15 at 22:28
  • yeah im sorry this is a previews version of my server.js I will try that. But on the last version I did define multer dest and still gave me this problem. – jsrosas Jan 16 '15 at 00:59
  • @mscdex Sorry i tried 'app.use(multer({dest: __dirname + '/public/uploads/'}));' and it gives me : events.js:72 throw er; // Unhandled 'error' event ^ Error: ENOENT, open – jsrosas Jan 16 '15 at 01:09

1 Answers1

1

Did you ever figure this out? I was getting the EAccess error as well.

To fix the issue I did the following.

I had to make sure that path = require('path') was included also not sure how old your question is compared to Multer releases but i looks like in version 1.0.3 you have to multer = require('multer') then below that upload = multer() also this is where you stick in the config information.

You end up with

var multer = require('multer'),
/*some config stuff for multer*/
    Limits = { fileSize: 10 * 1024 * 1024, files:1 };

/* specify one file so ppl can't flood the server with infinite file
  uploads or make it what you want but don't just leave it. Alternately 
  you can write the config stuff like the dest: value below. */

/*pass multer the configuration information and/or set config information*/
var upload = multer({dest: path.join(__dirname+'/uploads'),
                     limits: Limits
                    });

then do app.post like

app.post('/uploads', upload, function(req,res){
    // expose req.file to a variable or do some process by which you send it to your database.  
})

hope this helps.

Ravenous
  • 485
  • 4
  • 14
  • Thanks a lot its been a while since this question. I used app.use(multer({dest: __dirname + '/public/uploads/'})); – jsrosas Sep 18 '15 at 19:12