Skip to content

Instantly share code, notes, and snippets.

@gotomypc
Forked from marksilvis/s3upload.js
Created October 23, 2022 01:16
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 gotomypc/f4a594c6ad22db41760943fe6627ee91 to your computer and use it in GitHub Desktop.
Save gotomypc/f4a594c6ad22db41760943fe6627ee91 to your computer and use it in GitHub Desktop.
Node.js upload to AWS S3
// requires AWS SDK
var AWS = require('aws-sdk')
, fs = require('fs');
var s3 = new AWS.S3({
apiVersion: '2006-03-01',
accessKeyId: 'AccessKey',
secretAccessKey: 'SecretKey',
region: 'region'
});
fs.readFile('filename.jpg', function(err, data) {
var params = {
Bucket: 'bucket-name',
Key: 'bucket/directory',
Body: data,
ContentType: 'image/jpg'
};
s3.putObject(params, function(err, res) {
if (err) {
console.log('error');
console.log(err);
} else {
console.log('success');
console.log(res);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment