Created
July 18, 2018 07:40
-
-
Save mako34/25c926553dae10209e6766e079fccbc2 to your computer and use it in GitHub Desktop.
node S3 upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const AWS = require('aws-sdk'); | |
const s3 = new AWS.S3({ | |
accessKeyId: 'aaa', | |
secretAccessKey: 'bbb+oeyjn8zGANuDyCIY', | |
region: 'ap-southeast-2' | |
// accessKeyId: process.env.AWS_ACCESS_KEY, | |
// secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, | |
}); | |
const fileName = 'su.csv'; | |
const uploadFile = () => { | |
fs.readFile(fileName, (err, data) => { | |
if (err) throw err; | |
const params = { | |
Bucket: 'sb-communicate-files-dev', | |
Key: 'su.csv', | |
Body: data | |
}; | |
s3.upload(params, function(s3Err, data) { | |
if (s3Err) throw s3Err | |
console.log(`File uploaded successfully at ${data.Location}`) | |
}); | |
}); | |
}; | |
uploadFile(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment