-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathgetFile.js
More file actions
26 lines (19 loc) · 722 Bytes
/
getFile.js
File metadata and controls
26 lines (19 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const Responses = require('../common/API_Responses');
const S3 = require('../common/S3');
const bucket = process.env.bucketName;
exports.handler = async event => {
console.log('event', event);
if (!event.pathParameters || !event.pathParameters.fileName) {
// failed without an fileName
return Responses._400({ message: 'missing the fileName from the path' });
}
let fileName = event.pathParameters.fileName;
const file = await S3.get(fileName, bucket).catch(err => {
console.log('error in S3 get', err);
return null;
});
if (!file) {
return Responses._404({ message: 'Failed to read data by filename' });
}
return Responses._200(file);
};