Skip to content

Instantly share code, notes, and snippets.

@dariusc93
Created December 29, 2013 18:49
Show Gist options
  • Save dariusc93/8173472 to your computer and use it in GitHub Desktop.
Save dariusc93/8173472 to your computer and use it in GitHub Desktop.
module.exports = {
index:function(req,res){//get /test in routes.js
res.view('test');
},
upload:function(req,res){//post /upload in routes.js
console.log(req.files.uploadfile);
var path = '/home/projects/upload/'+req.files.uploadfile.name;
require('fs').rename(req.files.uploadfile.path,path,function(err){
if(err) throw err;
fs.chmodSync(path,440);//for *nix systems
res.redirect('/test');
});
},
_config: {}
};
doctype html
html
head
title File Upload
body
form(action='/upload',method='post',enctype='multipart/form-data')
input(type='file',name='uploadfile')
input(type='hidden', name='_csrf', value='#{_csrf}')
button(type='submit') Upload
@jdcauley
Copy link

jdcauley commented Jan 6, 2014

I'm probably missing something really dumb, the file upload appears to be successful but the file isn't on the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment