-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaws.js
More file actions
32 lines (29 loc) · 728 Bytes
/
aws.js
File metadata and controls
32 lines (29 loc) · 728 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
27
28
29
30
31
32
const aws = require("aws-sdk");
const { AWS_SECRET_KEY, AWS_ACCESS_KEY } = process.env;
const s3 = new aws.S3({
secretAccessKey: AWS_SECRET_KEY,
accessKeyId: AWS_ACCESS_KEY,
region: "ap-northeast-2",
});
const getSignedUrl = ({ key }) => {
return new Promise((resolve, reject) => {
s3.createPresignedPost(
{
Bucket: "image-upload-tutorial",
Fields: {
key,
},
Expires: 300,
Conditions: [
["content-length-range", 0, 50 * 1000 * 1000],
["starts-with", "$Content-Type", "image/"],
],
},
(err, data) => {
if (err) reject(err);
resolve(data);
}
);
});
};
module.exports = { s3, getSignedUrl };