moving files under folder 'portal', create folder services and add upload service
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@43614 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
dccf449e80
commit
411f437f45
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"name": "trunk",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"body-parser": "^1.15.2",
|
||||||
|
"express": "^4.14.0",
|
||||||
|
"multer": "^1.1.0"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
var express = require("express");
|
||||||
|
var bodyParser = require("body-parser");
|
||||||
|
var multer = require("multer");
|
||||||
|
var app = express();
|
||||||
|
|
||||||
|
app.use(bodyParser.json());
|
||||||
|
app.use(bodyParser.urlencoded({ extended: true }));
|
||||||
|
|
||||||
|
app.use(function(req, res, next) {
|
||||||
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post("/upload", multer({dest: "./uploads/"}).array("uploads[]", 12), function(req, res) {
|
||||||
|
var filepath = __dirname+"/"+req.files[0].path;
|
||||||
|
console.info(req.files[0]);
|
||||||
|
console.info("PAth:::::::"+filepath);
|
||||||
|
|
||||||
|
// var responseData;
|
||||||
|
// fs = require('fs')
|
||||||
|
// fs.readFile(__dirname+"/"+req.files[0].path, 'utf8', function (err,data) {
|
||||||
|
// if (err) {
|
||||||
|
// responseData= "error";
|
||||||
|
// console.log(err);
|
||||||
|
// }
|
||||||
|
// console.log(data);
|
||||||
|
// responseData=data;
|
||||||
|
// });
|
||||||
|
// req.files[0].data=responseData;
|
||||||
|
// res.send(req.files);
|
||||||
|
res.sendFile(filepath);
|
||||||
|
var fs = require('fs');
|
||||||
|
fs.stat(filepath, function (err, stats) {
|
||||||
|
console.log(stats);//here we got all information of file in stats variable
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
return console.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.unlink(filepath,function(err){
|
||||||
|
if(err) return console.log(err);
|
||||||
|
console.log('file deleted successfully');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
app.get('/get/d6bd36a06762e2f0da891f9670fcb2b0', function(req, res) {
|
||||||
|
res.sendFile('uploads/d6bd36a06762e2f0da891f9670fcb2b0')
|
||||||
|
})
|
||||||
|
var server = app.listen(8000, function() {
|
||||||
|
console.log("Listening on port %s...", server.address().port);
|
||||||
|
});
|
Loading…
Reference in New Issue