leeseohyeon

파일 다운로드 수정

This diff is collapsed. Click to expand it.
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
19 "morgan": "~1.9.1", 19 "morgan": "~1.9.1",
20 "mysql": "^2.18.1", 20 "mysql": "^2.18.1",
21 "passport": "^0.4.1", 21 "passport": "^0.4.1",
22 - "pug": "2.0.0-beta11", 22 + "pug": "^3.0.0",
23 "request": "^2.88.2" 23 "request": "^2.88.2"
24 } 24 }
25 } 25 }
......
...@@ -9,6 +9,25 @@ var S3 = require('../modules/s3/s3'); ...@@ -9,6 +9,25 @@ var S3 = require('../modules/s3/s3');
9 9
10 10
11 11
12 +router.get('/:name', function (req, res, next) {
13 + var file_name = req.params.name; // test.txt
14 + var user_id = req.query.id;
15 + var curPath = req.query.cur; // /folder1/folder2/
16 +
17 + var targetFile = (curPath + file_name).substring(1); // folder1/folder2/test.txt
18 +
19 + var s3 = new AWS.S3();
20 + var params = {
21 + Bucket: S3.BUCKET_NAME,
22 + Key: 'drive/' + user_id + '/' + targetFile,
23 + };
24 +
25 + res.attachment(file_name);
26 + var fileStream = s3.getObject(params).createReadStream();
27 + fileStream.pipe(res);
28 +});
29 +
30 +/*
12 // /file/download/:name 31 // /file/download/:name
13 router.get('/:name', function (req, res) { 32 router.get('/:name', function (req, res) {
14 var file_name = req.params.name; // test.txt 33 var file_name = req.params.name; // test.txt
...@@ -20,14 +39,18 @@ router.get('/:name', function (req, res) { ...@@ -20,14 +39,18 @@ router.get('/:name', function (req, res) {
20 S3.downloadFile2(S3.BUCKET_NAME, user_id, targetFile, function (result, downloadDir) { 39 S3.downloadFile2(S3.BUCKET_NAME, user_id, targetFile, function (result, downloadDir) {
21 if (result){ 40 if (result){
22 res.download(downloadDir, function (err) { 41 res.download(downloadDir, function (err) {
23 - fs.unlink(downloadDir, function (err) { 42 + if (err){
43 + console.log(err);
44 + }else{
24 console.log('download success'); 45 console.log('download success');
25 - }); 46 + }
26 }); 47 });
27 }else{ 48 }else{
28 - res.status(404).send({error: 'download error'}); 49 + res.send({error: 'download error'});
29 } 50 }
30 }); 51 });
31 }); 52 });
53 +*/
54 +
32 55
33 module.exports = router; 56 module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
......
1 { 1 {
2 - "accessKeyId": "ASIAZQ5XTMMF77IHPTR6", 2 + "accessKeyId": "ASIAZQ5XTMMFXPQFN3NS",
3 - "secretAccessKey": "IIDj5U3n6603WcAOf2OMTj2V6urKuGQaRGXABtVd", 3 + "secretAccessKey": "TcMI1ZR/XCHWTp+RXbXDYmoUUb589qOEKVCgrp9s",
4 - "sessionToken": "FwoGZXIvYXdzENH//////////wEaDLvwZHLSr6GbUZyD0yLDAVKxxzxNeyC41xtvOmvV9Xmeor5N/Uy6byi1/D/9K6OoGSwdgPNlyyz5EzCsB3UDWtyWGSmIX9PreX0FX2wnD5/VHDl9QibRMUpXOBlg95BNHrfx0e7Srfn6a1GY8eN9ntiqiv7DuS3jV7I7L9NOE218dxDnt4hul8gStVZ4urSXlz4KUAXLucCbF4y2c/KuDVqKPM/9+MQgnL6f3bHThwNEhZhm4CjyHQYZgB2eGd9HYi95RYC9NglBi1gH60Iao8AELSi8wc32BTItNSdy9ymXld6zjj9OnqNzUZdm+GdCX8qFQ87nzVzmX7kHEOWnK9x+4zTHbGXx", 4 + "sessionToken": "FwoGZXIvYXdzENb//////////wEaDNgXTHMODoBOdUpzkCLDAbECc2/FubNowruTAgVlYoP1DSxpCPyKWCZAgNyMak8XUFwQycZDMvPgj/hl+Jn+a8yn2xktkSZP3yRQ2UcTm0WQeWKt94HzatAXBT17B2BBLZOPjMgFWiG4Rgqw48tyT5po3/M84gs5p+x/0AGh7oVQ9VlqoZcgdCRfXUBD9oQ7xkb74AiZ6kZKu5DSNMyIhzzXFrtIXMK+0La9AmfuAhytmTlG9XXp1UhYzubBajB6b2OW/Ce4yKs7Y7UzRr3LERyLCCj9zM72BTIt+BGOkTrbTV65QeFYRmPbKB7OlRsIfdyd67uKLQfSGmsSgp0SFw7sZKcRRODL",
5 "region": "us-east-1" 5 "region": "us-east-1"
6 } 6 }
...\ No newline at end of file ...\ No newline at end of file
......
1 -안녕
...\ No newline at end of file ...\ No newline at end of file
1 +[object Object]
...\ No newline at end of file ...\ No newline at end of file
...@@ -106,7 +106,7 @@ var S3 = { ...@@ -106,7 +106,7 @@ var S3 = {
106 } else { 106 } else {
107 if (data) { 107 if (data) {
108 console.log("Get File Success"); 108 console.log("Get File Success");
109 - callback(true, data.body); 109 + callback(true, data.body.toString());
110 } 110 }
111 } 111 }
112 }) 112 })
......
...@@ -5775,9 +5775,9 @@ ...@@ -5775,9 +5775,9 @@
5775 } 5775 }
5776 }, 5776 },
5777 "http-proxy": { 5777 "http-proxy": {
5778 - "version": "1.18.0", 5778 + "version": "1.18.1",
5779 - "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.0.tgz", 5779 + "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz",
5780 - "integrity": "sha512-84I2iJM/n1d4Hdgc6y2+qY5mDaz2PUVjlg9znE9byl+q0uC3DeByqBGReQu5tpLK0TAqTIXScRUV+dg7+bUPpQ==", 5780 + "integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==",
5781 "dev": true, 5781 "dev": true,
5782 "requires": { 5782 "requires": {
5783 "eventemitter3": "^4.0.0", 5783 "eventemitter3": "^4.0.0",
......