Simplest way to upload binary image data to S3 as of 2023?

I have a library that generates binary image data and I would like to upload this as a PNG to an S3 bucket. What is the simplest way to do this in Meteor, as of 2023?

(I am already using slingshot for client-side uploads.)

Since my functions use streams, I convert the data to stream first. For buffer data, I use Readable Stream | Node.js v19.6.0 Documentation

And then use any package or code out there to stream data to s3 bucket.

could this work for you?!

const blobData = imageData.slice(23) // this is to remove the root data of your image "data:image/png;base64 ...
yourFileToUpload = b64toBlob(blobData, 'image/png')

// the function

const b64ToBlob = (b64Data, contentType, sliceSize) => {
  let byteNumbers, i, slice
  let offset = 0
  const byteCharacters = atob(b64Data)
  const byteArrays = []
  sliceSize = sliceSize || 512
  while (offset < byteCharacters.length) {
    slice = byteCharacters.slice(offset, offset + sliceSize)
    byteNumbers = []
    for (i = 0; i < slice.length; ++i) {
    byteArrays.push(new Uint8Array(byteNumbers))
    offset += sliceSize
  return new Blob(byteArrays, { type: contentType })

1 Like