I am very new to using AWS (Literally as of a few days ago), and am trying to upload images to an S3 bucket using API Gateway.
I am following This Tutorial on youtube which shows how to set everything up in AWS and then use Postman to call my API and add my image to S3.
This all works fine and the POST request functions as expected and adds the file to S3. However, when I try to view the file in S3 by clicking 'Open', I get the following instead of the image I sent:
Also, if I try to download the file and view it, it says:
The file “myfile.jpeg” could not be opened. It may be damaged or use a file format that Preview doesn’t recognise.
There doesn't seem to be an issue with the image itself, because when I upload it directly to the S3 bucket rather than through my API Gateway, the image shows up just as expected. I also followed the tutorial to a T and so doubt there are issues with permissions or anything in AWS itself (but am open to being challenged on this).
So I expect that there is some sort of issue occurring when the image is transferred, but again I am pretty new to this and so am not sure how to go about checking that.
Any help would be greatly appreciated.
After a lot of learning I finally managed to solve the problem.
It turns out that under my binary media types in my API settings I had put "/image/jpeg" instead of "image/jpeg".
Since my POST request had it's Content-Type set to "image/jpeg", this meant that my API was taking in the base-64 encoded data from the request and sending it through to S3 as-is instead of treating it as a binary data, hence the formatting issues when trying to open the file from S3.
So the solution was simply to update my binary media types to include "image/jpeg" instead.
Thanks to @JohnRotenstein for guiding me in the right direction by spotting that the image was base-64 encoded and for the useful links in the comments. I have learned a lot :)