Showing
2 changed files
with
18 additions
and
10 deletions
... | @@ -16,6 +16,7 @@ router.get('/:name', function (req, res) { | ... | @@ -16,6 +16,7 @@ router.get('/:name', function (req, res) { |
16 | var user_id = req.query.id; | 16 | var user_id = req.query.id; |
17 | 17 | ||
18 | var targetFile = curPath.substring(1) + file_name; // folder1/folder2/test.txt | 18 | var targetFile = curPath.substring(1) + file_name; // folder1/folder2/test.txt |
19 | + console.log(targetFile); | ||
19 | 20 | ||
20 | 21 | ||
21 | S3.downloadFile3(S3.BUCKET_NAME, user_id, targetFile, function (result, downloadDir) { | 22 | S3.downloadFile3(S3.BUCKET_NAME, user_id, targetFile, function (result, downloadDir) { |
... | @@ -29,7 +30,7 @@ router.get('/:name', function (req, res) { | ... | @@ -29,7 +30,7 @@ router.get('/:name', function (req, res) { |
29 | } | 30 | } |
30 | }) | 31 | }) |
31 | }else{ | 32 | }else{ |
32 | - res.send({ err: 'download error'}) | 33 | + res.send({ err: 'no such file'}) |
33 | } | 34 | } |
34 | }) | 35 | }) |
35 | }); | 36 | }); | ... | ... |
... | @@ -166,16 +166,23 @@ var S3 = { | ... | @@ -166,16 +166,23 @@ var S3 = { |
166 | Bucket: bucketName, | 166 | Bucket: bucketName, |
167 | Key: 'drive/' + userId + '/' + targetFile | 167 | Key: 'drive/' + userId + '/' + targetFile |
168 | }; | 168 | }; |
169 | - try { | 169 | + s3.getObject(params) |
170 | - var stream = s3.getObject(params).createReadStream().pipe(file); | 170 | + .createReadStream() |
171 | - stream.on('end', function(){ | 171 | + .on('error', function(e){ |
172 | - console.log('end!'); | ||
173 | - callback(true, tempDownloadDir); | ||
174 | - }); | ||
175 | - }catch(err){ | ||
176 | - console.log('no such file', err); | ||
177 | callback(false); | 172 | callback(false); |
178 | - } | 173 | + }) |
174 | + .pipe(file) | ||
175 | + .on('close', function(){ | ||
176 | + callback(true, tempDownloadDir); | ||
177 | + }) | ||
178 | + //try { | ||
179 | + // var file = s3.getObject(params); | ||
180 | + // file.createReadStream().pipe(file); | ||
181 | + // callback(true, tempDownloadDir); | ||
182 | + //} catch (err) { | ||
183 | + // console.log('no such file'); | ||
184 | + // callback(false); | ||
185 | + //} | ||
179 | }else{ | 186 | }else{ |
180 | callback(false); | 187 | callback(false); |
181 | } | 188 | } | ... | ... |
-
Please register or login to post a comment