0

Using a third-party API I receive a PNG attachement back from my request with:

Headers:

Content-Type: "image/png"
Content-Disposition: attachment; filename*=UTF-8''Api-URL-2021-05-13T09-21-31-094_clipped_rev_1.png

And

data
that looks like this:

data: `�PNGrn...IHDR ........`

I can see the image displayed in postman and looks ok.

The issue is I want to save that image to an

S3 bucket
and convert this attachment to something I can save in
S3
.

Can I convert this

data
to something that I can save in my S3 bucket?

Here is my S3 function:

function saveFile(data: Buffer | Uint8Array | Blob | string | Readable) {
  const putParams = {
    Bucket: 'my-bucket',
    Key: 'test-file',
    Body: data,
  };
  s3.putObject(putParams, (putErr, putData) => {
    if (putErr) {
      console.error(putErr);
    } else {
      console.log(putData);
    }
  });
}

And

Body
can be any of these types:
Buffer | Uint8Array | Blob | string | Readable
according to
TypeScript

Anonymous Asked question May 13, 2021