Apig + lambda-proxy + multipart-formdata

I managed to use the framework to create my service and post a request with content-type “multipart/form-data”. Although I was able to parse the different parts in the payload, it seems the “image-file” part arrives in lambda in the form of:

Content-Disposition: form-data; name=“uploadFile”; filename=“productImage.jpg”\r\nContent-Type: image/jpeg\r\n\r\n����\u0000\u0010JFIF\u0000\u0001\u0001\u0000\u0000\u0001\u0000\u0001\u0000\u0000��\u0000C\u0000\u0003\u0002\u0002\u0002\u0002\u0002\u0003\u0002\u0002\u0002\u0003\u0003\u0003\u0003\u0004\u0006\u0004\u0004\u0004\u0004\u0004\b\u0006\u0006\u0005\u0006\t\b\n\n\t\b\t\t\n\f\u000f\f\n\u000b\u000e\u000b\t\t\r\u0011\r\u000e\u000f\u0010\u0010\u0011\u0010\n\f\u0012\u0013\u0012\u0010\u0013\u000f\u0010\u0010\u0010��\u0000C\u0001\u0003\u0003\u0003\u0004\u0003\u0004\b\u0004\u0004\b\u0010\u000b\t\u000b\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010\u0010��\u0000\u0011\b\u0002X\u0001�\u0003\u0001"\u0000\u0002\u0011\u0001\u0003\u0011\u0001��\u0000\u001f\u0000\u0000\u0001\u0005\u0001\u0001\u0001\u0001\u0001\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b��\u0000�\u0010\u0000\u0002\u0001\u0003\u0003\u0002\u0004\u0003\u0005\u0005\u0004\u0004\u0000\u0000\u0001}\u0001\u0002\u0003\u0000\u0004\u0011\u0005\u0012!1A\u0006\u0013Qa\u0007"q\u00142���\b#B��\u0015R��$3br�\t\n\u0016\u0017\u0018\u0019\u001a%&’()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz���������������������������������������������������������������������������\u0000\u001f\u0001\u0000\u0003\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b��\u0000�\u0011\u0000\u0002\u0001\u0002\u0004\u0004\u0003\u0004\u0007\u0005\u0004\u0004\u0000\u0001\u0002w\u0000\u0001\u0002\u0003\u0011\u0004\u0005!1\u0006\u0012AQ\u0007aq\u0013"2�\b\u0014B����\t#3R�\u0015br�\n\u0016$4�%�\u0017\u0018\u0019\u001a&’() … (rest of the image).

what is unmanageable.
I already tried to convert that string to a Buffer, utf-8, base64, but the image wont convert into a readable file. Does anybody had a similar issue?

2 Likes

I just ran into this same issue while trying to parse PDFs that are posted in multipart/form-data requests.

Did you configure any binary media types?
If not, then just search the forum. You either need to configure binary media types manually or use some plugin.
(you most likely don’t use Java I guess but check this on how to configure binary media types manually: https://github.com/bbilger/jrestless-examples/blob/master/aws/gateway/aws-gateway-binary/README.md)

1 Like

It won’t work for everyone or every situation but my preference is to upload them to S3 using a signed URL then trigger a Lambda when a file is created in the bucket.

You need to config Binary support for media types.
Check this: