-
Notifications
You must be signed in to change notification settings - Fork 1
/
s3.js
35 lines (24 loc) · 779 Bytes
/
s3.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
const AWS = require('aws-sdk');
const { randomBytes } = require('crypto');
const { aws_config } = require('./config');
const region = aws_config.region
const bucketName = aws_config.bucketName
const accessKeyId = aws_config.accessKeyId
const secretAccessKey = aws_config.secretAccessKey
const signatureVersion = aws_config.signatureVersion
const s3 = new AWS.S3({
region,
accessKeyId,
secretAccessKey,
signatureVersion
})
async function createUploadURL() {
const params = ({
Bucket: bucketName,
Key: await randomBytes(20).toString('hex'),
Expires: 60 // url will expire after 1 min
});
const uploadURL = await s3.getSignedUrlPromise('putObject', params)
return uploadURL;
}
module.exports = { createUploadURL };