-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (39 loc) · 1.03 KB
/
index.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const express=require('express');
const app=express();
const PORT=3200;
const AWS = require('aws-sdk');
// Our default route
app.get('/',(req,res)=>{
AWS.config.update({
accessKeyId: "",
secretAccessKey: ""
});
let s3 = new AWS.S3();
async function getImage(){
const data = s3.getObject(
{
Bucket: '',
Key: ""
}
).promise();
return data;
}
getImage()
.then((img)=>{
let image="<img src='data:image/jpeg;base64," + encode(img.Body) + "'" + "/>";
let startHTML="<html><body></body>";
let endHTML="</body></html>";
let html=startHTML + image + endHTML;
res.send(html)
}).catch((e)=>{
res.send(e)
})
function encode(data){
let buf = Buffer.from(data);
let base64 = buf.toString('base64');
return base64
}
})
app.listen(PORT,()=>{
console.log(`Web Server running on port ${PORT}`);
});