leeseohyeon

파일 다운로드 에러 처리

......@@ -16,6 +16,7 @@ router.get('/:name', function (req, res) {
var user_id = req.query.id;
var targetFile = curPath.substring(1) + file_name; // folder1/folder2/test.txt
console.log(targetFile);
S3.downloadFile3(S3.BUCKET_NAME, user_id, targetFile, function (result, downloadDir) {
......@@ -29,7 +30,7 @@ router.get('/:name', function (req, res) {
}
})
}else{
res.send({ err: 'download error'})
res.send({ err: 'no such file'})
}
})
});
......
......@@ -166,16 +166,23 @@ var S3 = {
Bucket: bucketName,
Key: 'drive/' + userId + '/' + targetFile
};
try {
var stream = s3.getObject(params).createReadStream().pipe(file);
stream.on('end', function(){
console.log('end!');
callback(true, tempDownloadDir);
});
}catch(err){
console.log('no such file', err);
s3.getObject(params)
.createReadStream()
.on('error', function(e){
callback(false);
}
})
.pipe(file)
.on('close', function(){
callback(true, tempDownloadDir);
})
//try {
// var file = s3.getObject(params);
// file.createReadStream().pipe(file);
// callback(true, tempDownloadDir);
//} catch (err) {
// console.log('no such file');
// callback(false);
//}
}else{
callback(false);
}
......