2

How does one upload an existing image to AWS S3 using the image's URL (I am using the AWS SDK for Node.js)? I am trying to migrate images from Parse, which I can access the URLs of. I am something set up like this:

let params = {
    Key: 'sampleurl.png',
    Bucket: Config.get('server.s3.bucket'),
    Body: ???, // ?
    ACL: 'public-read'
};

s3Client.upload(params, (err, data) => {
    if (err) { throw err; }

    return data.Location;
});

How would I re-upload, for example, an image at 'http://files.parsetfss.com/something/something.png' to AWS?

user2901933
  • 149
  • 3
  • 9
  • have not done this migration of "files.parse.com" yet but, you could check this proj out : https://github.com/parse-server-modules/parse-files-utils using the report, IMO u can just access the urls (http GET) on http without a master or an api key. So you can script the migration to S3 using the public urls in the report from the linked project – Robert Rowntree Jul 18 '16 at 21:36
  • Consider downloading the images first and the uploading them to S3. It seems this post could give you tips about the first part: http://stackoverflow.com/questions/12740659/downloading-images-with-node-js – Conti Jul 19 '16 at 07:46

1 Answers1

1

I'm using sharp to upload images to s3 from url:

sharp(fileUrl).toBuffer(function(err, outputBuffer) {
  if (err) { 
    reject(err); 
  }

  s3client.upload({
    ACL:'public-read', 
    Body: outputBuffer
  }, function(err, result) {
    if (err) { 
      reject(err); 
    }

    resolve(result.Location);

  });

});

Maybe will help you ;)

  • 2
    This answer didn't work for me, kept getting a, "Input file is missing or of an unsupported image format" error but the following answer using node's request module worked first try - https://stackoverflow.com/q/22186979/907388 – pbojinov Nov 06 '17 at 23:43