-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaws.js
39 lines (31 loc) · 1.02 KB
/
aws.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
// aws config
const aws = require('aws-sdk');
const config = require('./config.js');
const path = require('path');
const fs = require('fs');
aws.config.update({
"accessKeyId": config.AWS_ACCESS_KEY, // process.env.AWS_ACCESS_KEY,
"secretAccessKey": config.AWS_SECRET_KEY, // process.env.AWS_SECRET_KEY,
"region": config.AWS_REGION // process.env.AWS_REGION
});
const s3 = new aws.S3();
const filename = process.argv[2];
// grab the ile data
var file = fs.readFileSync(filename);
// get the name for the file
var name = path.basename(filename);
var image_url = "https://s3-" + config.AWS_REGION + '.amazonaws.com/' + config.AWS_BUCKET + '/' + name;
var params = {
"Bucket": config.AWS_BUCKET,
"Key": name,
"Body": file,
"ContentType": "image/png",
"ACL": "public-read"
};
s3.putObject(params, function (err, res) {
if (err) {
console.log("Error uploading data: ", err);
} else {
console.log("Successfully uploaded data to ", 'https://shots.ohthatsnice.net/' + name);
}
});