AWS Deep Dive
- author:: Nathan Acks
- date:: 2022-10-17
Amazon API Gateway
Continued notes about the Amazon API Gateway.
Working with REST APIs
Working With Binary Media Types for REST APIs (Continued)
While binary media types need to be specified individually, API Gateway does support wildcarding. In particular,
*/* will match all files, though given the sometimes strange behavior of API Gateway that seems potentially inadvisable; I suspect something like
image/* may work better (though even here there are potential problems - for example, handling SVGs).
When converting incoming binary data to a base64 encoded string, a mapping template can be provided in order to provide the appropriate surrounding graffiti (normally JSON blob structure). For obvious reasons, a mapping is not necessary (or advisable) when converting a base64 string to a binary stream.
(The API examples AWS provides in the documentation for uploading base64 encoded binary data use
Content-Type: application/json with a body that’s a raw - unwrapped! - base64 string. While this makes sense within the context of API Gateway, abusing
Content-Type in this fashion just seems really bad to me.)