Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NodeJS - Upload local (file) image to AWS S3 from stream with public access.
const AWS = require('aws-sdk');
const fs = require('fs');
AWS.config.update({ accessKeyId: 'ACCESSKEYID', secretAccessKey: 'SECRETACCESSKEY', region: 'eu-west-3'});
const fileStream = fs.createReadStream('/path/to/your/image.png');
fileStream.on('error', function (err) {
if (err) { throw err; }
});
fileStream.on('open', function () {
const s3 = new AWS.S3();
s3.putObject({
Bucket: 'your-bucket',
Key: 'file-renamed.png',
ACL: 'public-read',
Body: fileStream,
Metadata: { 'type': 'png', 'user': 'Dimitri DO BAIRRO' }
}, function (err) {
if (err) { throw err; }
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.