Trying to upload a png
file using S3-for-Google-Apps-Script library to S3 bucket:
// get the image blob
const imgBlob = UrlFetchApp.fetch('imageUrl').getBlob();
// init S3 instance
const s3 = S3.getInstance(awsAccessKeyId, awsSecretKey);
// upload the image to S3 bucket
s3.putObject(bucketName, 'test.png', imgBlob, { logRequests:true });
The file is uploading to S3 but not in a perfect way! It looks like this:
If I download the image and open getting the error
:
"It may be damaged or use a file format that Preview doesn’t recognize."
So, how can I upload a .png
file to amazon S3 bucket?
I can correctly upload the image when 'base64' is used to s3.putObject()
:
const base64 = Utilities.base64Encode(imgBlob.getBytes());
s3.putObject(bucketName, 'test.png', base64, { logRequests:true });
// go to S3 and clicking on the link I can see the base64 string
But this is uploading as String
e.g. when I go S3 & click on test.png
I see something like this: "iVBORw0KGgoAAAANSUhEUgAAAgAAAAI ... II="
, but I want to see the actual image, not a String
.