-
Notifications
You must be signed in to change notification settings - Fork 0
/
webserver.js
53 lines (38 loc) · 1.06 KB
/
webserver.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
50
51
52
53
const express=require('express');
const app=express();
const PORT=3200;
const AWS = require('aws-sdk');
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 startHTML="<html><body></body>";
let endHTML="</body></html>";
let html=startHTML + "<img src='data:image/png;base64," + encode(img.Body) + "'" + "/>" + 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}`);
});