Skip to content

Instantly share code, notes, and snippets.

@aug2uag
Last active December 12, 2021 08: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 aug2uag/d276c0337597de0465890fe5380c8ca4 to your computer and use it in GitHub Desktop.
Save aug2uag/d276c0337597de0465890fe5380c8ca4 to your computer and use it in GitHub Desktop.
NodeJS S3 upload image from URL
// https://stackoverflow.com/a/25564742/1546710
var AWS = require('aws-sdk');
var request = require('request');
AWS.config.loadFromPath('./config.json');
var s3 = new AWS.S3();
function put_from_url(url, bucket, key, callback) {
request({
url: url,
encoding: null
}, function(err, res, body) {
if (err)
return callback(err, res);
s3.upload({
Bucket: bucket,
Key: key,
ContentType: res.headers['content-type'],
ContentLength: res.headers['content-length'],
Body: body // buffer
}, callback);
})
}
put_from_url('https://public.nftstatic.com/static/nft/res/f2a4326f37474c4eb216df45995fa4ee.png', 'buck37', 'uniqu3K3y', function(err, res) {
if (err)
throw err;
console.log('Uploaded data successfully!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment