Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload canvas data uri to amazon s3 server

Right now, I've passed the canvas data URI string

(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAADwCAYAAABxLb1rAAAgAElEQVR..... )

to my hapi (NodeJS) server.

My question is:

What are my next steps to "stream"/upload this data to Amazon S3 and create an actual image there?

like image 474
Kim Tim Avatar asked Nov 03 '25 19:11

Kim Tim


1 Answers

before send object to s3 you must transform base64 to buffer and after send, for example:

var buf = new Buffer(b64string, 'base64');
s3.putObject({/*some  params*/, Body: buf}, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

After this you send data to s3 and you will can open image without decode.

Good luck!

like image 80
siavolt Avatar answered Nov 05 '25 11:11

siavolt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!