Last active
December 19, 2020 12:56
-
-
Save myke11j/0b47fbaf91f2b74061159a11bd02f95a to your computer and use it in GitHub Desktop.
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: process.env.AWS_ACCESS_KEY, | |
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY | |
}); | |
const fileName = 'contacts.csv'; | |
const uploadFile = () => { | |
fs.readFile(fileName, (err, data) => { | |
if (err) throw err; | |
const params = { | |
Bucket: 'testBucket', // pass your bucket name | |
Key: 'contacts.csv', // file will be saved as testBucket/contacts.csv | |
Body: JSON.stringify(data, null, 2) | |
}; | |
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