As in the title, I can't seem to get it to work, i'm following the high level guide detailed here but any images uploaded seem to be blank.
What i've set up:
/images/{object} - PUT
> Integration Request
AWS Region: ap-southeast-2
AWS Service: S3
AWS Subdomain [bucket name here]
HTTP method: PUT
Path override: /{object}
Execution Role [I have one set up]
> URL Path Paramaters
object -> method.request.path.object
I'm trying to use Postman to send a PUT request with Content-Type: image/png and the body is a binary upload of a png file.
I've also tried using curl:
curl -X PUT -H "Authorization: Bearer [token]" -H "Content-Type: image/gif" --upload-file ~/Pictures/bart.gif https://[api-url]/dev/images/cool.gif
It creates the file on the server and the size seems to be double what ever was uploaded, when viewed I just get "image has an error".
When I try with .txt files (content-type: text/plain) it seems to work though.
Any ideas?
After reading alot and chatting to AWS technical support, the problem seems to be that you can't do binary uploads through API Gateway as anything that passes through automatically goes through a UTF-8 encode.
There are a few workarounds for this I can think of, my solution will be to base64 the files before upload and trigger a lambda when they hit the bucket to decode them
This is a old post, but I got a solution.
AWS now support binary upload through APIGateway READ.
In general, go to your API settings, and add a Binary Media type.
After that, you can handle the file in base64
Related
I am using AWS API Gateway put method to post an image to S3 bucket. In API Gateway settings when I add / in Binary Media Types I get the following error message
Access to fetch at ‘some_invokation_request/my_s3_bucket/image.png’ from origin ‘http://localhost:3001’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.
When I remove / from Binary media types in settings I can post an image and when I check the posted image in S3 it's messed up.
I'll post the original image and S3 image
Apparently this is an open issue right now and you can find further details here
I believe you have two different errors present. One is CORS related and the other is the upload of an image getting messed up. I don't think they are necessarily related. I've hit the same issue with the image upload showing the tiny white square but faced no CORS issue.
For me, the problem turned out to be trying to combine the use of Convert to Binary (if needed) and a mapping template on the Integration Request. According to the documentation (and my experience as well), if a mapping template is defined, APIGW doesn't run the Convert to Binary passthrough functionality. What gets passed to the S3 bucket for saving is a base64 encoded string instead of actual binary, thus the messed up image.
Excerpt from the linked documentation:
"On the contentHandling property of the Integration resource, set CONVERT_TO_BINARY. Set WHEN_NO_MATCH as the passthroughBehavior property value without defining a mapping template. This enables API Gateway to invoke the passthrough template."
What am I missing here?
I'm able to list objects no problem using the aws cli and this command:
aws s3 ls s3://bucket.mycompany.com/parent-dir1/parent-dir2/
But using the REST API via Postman, an equivalent request returns an empty response.
Tool: Postman
Method: GET
URl:
https://bucket.mycompany.com.s3.amazonaws.com/parent-dir1/parent-dir2/?list-type=2
Auth:
Headers:
I've tried with no headers and with x-amz-content-sha256 UNSIGNED-PAYLOAD
Message says "This is a duplicate header and will be overridden..." when I try to use this header
Response:
Status 200 but response is empty(There are MANY files in parent-dir2).
Eureka! Found the answer in the AWS docs here
Winner ended up being:
https://bucket.mycompany.com.s3.amazonaws.com/?list-type=2&prefix=parent-dir1/parent-dir2/
Is it possible to download Zip file present in S3 using API Gateway alone.
Configurations:
Integration type : AWS Service (S3)
endpoint : GET
Content-Type: application/zip (or) application/octet-stream
A corrupted zip file is getting downloaded.
I could able to do a workaround using S3 presigned url and don't want to make the bucket public.
The file can get corrupted when some headers are missing from the upload PUT request. Please make sure the file is not-corrupted by downloading it manually and checking. If it's corrupted from the GET request only please make sure you include all the needed headers in the GET request too.
I created a API Gateway which is Integrated to use S3 bucket. I see that when I tried to retrieve the object I am getting a 200 response. However I am getting some ackward text(probably a base64 or binary text rather than the image. Can you please let me know the fix.
So the answer is set the following headers:-
I have a set of images stored on S3 that should be displayed on the browser. These images have a content type of application/octet-stream and can be viewed in Chrome and Firefox.
My understanding is that Internet Explorer cannot view application/octet-stream content, or it is unable to realize that the S3 object is actually an image.
I've tried to upload new versions of my images onto S3 and manually adding a Metadata Header/Value pair of Content-Type and image/png (using the S3 console, not CLI). However, I still see the same application/octet-stream on IE.
Is it possible to configure my application (Angular4/SpringBoot/Tomcat) to tell IE to look at that type of content, or am I looking at the wrong place in S3?
From my backend, where I set my AWS S3 api I was setting the response headers to 'application/octet-stream'.