Skip to content

Instantly share code, notes, and snippets.

@jpfong
Last active December 2, 2017 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpfong/bc11159e31edb3380551d4ab778f9a6b to your computer and use it in GitHub Desktop.
Save jpfong/bc11159e31edb3380551d4ab778f9a6b to your computer and use it in GitHub Desktop.
Put object in Amazon S3. Note: can only upload one file at a time
const aws = require('aws-sdk');
const s3 = new aws.S3();
var params = {
Bucket: 'bucket_name',
Key: 'file.png', // if you want to put in a directory, the key would be: 'directory_name/file_name.ext'
ACL: 'public-read', // to allow to access the file
Body: data // the data of the file
};
s3.putObject(params, (err, data) => {
if (err) {
console.error('Error uploading image: ', err);
} else {
console.log(data);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment