leeseohyeon

파일 다운로드 수정

This diff is collapsed. Click to expand it.
......@@ -19,7 +19,7 @@
"morgan": "~1.9.1",
"mysql": "^2.18.1",
"passport": "^0.4.1",
"pug": "2.0.0-beta11",
"pug": "^3.0.0",
"request": "^2.88.2"
}
}
......
......@@ -9,6 +9,25 @@ var S3 = require('../modules/s3/s3');
router.get('/:name', function (req, res, next) {
var file_name = req.params.name; // test.txt
var user_id = req.query.id;
var curPath = req.query.cur; // /folder1/folder2/
var targetFile = (curPath + file_name).substring(1); // folder1/folder2/test.txt
var s3 = new AWS.S3();
var params = {
Bucket: S3.BUCKET_NAME,
Key: 'drive/' + user_id + '/' + targetFile,
};
res.attachment(file_name);
var fileStream = s3.getObject(params).createReadStream();
fileStream.pipe(res);
});
/*
// /file/download/:name
router.get('/:name', function (req, res) {
var file_name = req.params.name; // test.txt
......@@ -20,14 +39,18 @@ router.get('/:name', function (req, res) {
S3.downloadFile2(S3.BUCKET_NAME, user_id, targetFile, function (result, downloadDir) {
if (result){
res.download(downloadDir, function (err) {
fs.unlink(downloadDir, function (err) {
if (err){
console.log(err);
}else{
console.log('download success');
});
}
});
}else{
res.status(404).send({error: 'download error'});
res.send({error: 'download error'});
}
});
});
*/
module.exports = router;
\ No newline at end of file
......
{
"accessKeyId": "ASIAZQ5XTMMF77IHPTR6",
"secretAccessKey": "IIDj5U3n6603WcAOf2OMTj2V6urKuGQaRGXABtVd",
"sessionToken": "FwoGZXIvYXdzENH//////////wEaDLvwZHLSr6GbUZyD0yLDAVKxxzxNeyC41xtvOmvV9Xmeor5N/Uy6byi1/D/9K6OoGSwdgPNlyyz5EzCsB3UDWtyWGSmIX9PreX0FX2wnD5/VHDl9QibRMUpXOBlg95BNHrfx0e7Srfn6a1GY8eN9ntiqiv7DuS3jV7I7L9NOE218dxDnt4hul8gStVZ4urSXlz4KUAXLucCbF4y2c/KuDVqKPM/9+MQgnL6f3bHThwNEhZhm4CjyHQYZgB2eGd9HYi95RYC9NglBi1gH60Iao8AELSi8wc32BTItNSdy9ymXld6zjj9OnqNzUZdm+GdCX8qFQ87nzVzmX7kHEOWnK9x+4zTHbGXx",
"accessKeyId": "ASIAZQ5XTMMFXPQFN3NS",
"secretAccessKey": "TcMI1ZR/XCHWTp+RXbXDYmoUUb589qOEKVCgrp9s",
"sessionToken": "FwoGZXIvYXdzENb//////////wEaDNgXTHMODoBOdUpzkCLDAbECc2/FubNowruTAgVlYoP1DSxpCPyKWCZAgNyMak8XUFwQycZDMvPgj/hl+Jn+a8yn2xktkSZP3yRQ2UcTm0WQeWKt94HzatAXBT17B2BBLZOPjMgFWiG4Rgqw48tyT5po3/M84gs5p+x/0AGh7oVQ9VlqoZcgdCRfXUBD9oQ7xkb74AiZ6kZKu5DSNMyIhzzXFrtIXMK+0La9AmfuAhytmTlG9XXp1UhYzubBajB6b2OW/Ce4yKs7Y7UzRr3LERyLCCj9zM72BTIt+BGOkTrbTV65QeFYRmPbKB7OlRsIfdyd67uKLQfSGmsSgp0SFw7sZKcRRODL",
"region": "us-east-1"
}
\ No newline at end of file
......
[object Object]
\ No newline at end of file
......@@ -106,7 +106,7 @@ var S3 = {
} else {
if (data) {
console.log("Get File Success");
callback(true, data.body);
callback(true, data.body.toString());
}
}
})
......
......@@ -5775,9 +5775,9 @@
}
},
"http-proxy": {
"version": "1.18.0",
"resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.0.tgz",
"integrity": "sha512-84I2iJM/n1d4Hdgc6y2+qY5mDaz2PUVjlg9znE9byl+q0uC3DeByqBGReQu5tpLK0TAqTIXScRUV+dg7+bUPpQ==",
"version": "1.18.1",
"resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz",
"integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==",
"dev": true,
"requires": {
"eventemitter3": "^4.0.0",
......