반응형
Server.js
/*Define dependencies.*/
var express=require("express");
var multer = require('multer');
var app=express();
var done=false;
/*Configure the multer.*/
app.use(multer({ dest: './uploads/',
rename: function (fieldname, filename) {
return filename+Date.now();
},
onFileUploadStart: function (file) {
console.log(file.originalname + ' is starting ...')
},
onFileUploadComplete: function (file) {
console.log(file.fieldname + ' uploaded to ' + file.path)
done=true;
}
}));
/*Handling routes.*/
app.get('/',function(req,res){
res.sendfile("index.html");
});
app.post('/api/photo',function(req,res){
if(done==true){
console.log(req.files);
res.end("File uploaded.");
}
});
/*Run the server.*/
app.listen(3000,function(){
console.log("Working on port 3000");
});
var express=require("express");
var multer = require('multer');
var app=express();
var done=false;
/*Configure the multer.*/
app.use(multer({ dest: './uploads/',
rename: function (fieldname, filename) {
return filename+Date.now();
},
onFileUploadStart: function (file) {
console.log(file.originalname + ' is starting ...')
},
onFileUploadComplete: function (file) {
console.log(file.fieldname + ' uploaded to ' + file.path)
done=true;
}
}));
/*Handling routes.*/
app.get('/',function(req,res){
res.sendfile("index.html");
});
app.post('/api/photo',function(req,res){
if(done==true){
console.log(req.files);
res.end("File uploaded.");
}
});
/*Run the server.*/
app.listen(3000,function(){
console.log("Working on port 3000");
});
index.html
반응형
'웹프로그래밍 > node.js & Typescript' 카테고리의 다른 글
[node.js] Most middleware (like logger) is no longer bundled with Express and must be installed separately... (0) | 2015.06.09 |
---|---|
[node.js] express cookie-parser (0) | 2015.06.09 |
[node.js] Check synchronously if file/directory exists in Node.js (0) | 2015.06.09 |
[node.js] bodyParser deprecated (0) | 2015.06.09 |
[node.js] .router' is deprecated! (0) | 2015.06.09 |