# Apig + lambda-proxy + multipart-formdata

**URL:** <https://forum.serverless.com/t/apig-lambda-proxy-multipart-formdata/2548>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [August 22, 2017, 2:12pm UTC](https://forum.serverless.com/t/apig-lambda-proxy-multipart-formdata/2548 "2017-08-22T14:12:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rcfrias](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@rcfrias](https://forum.serverless.com/u/rcfrias)\
**Post date:** [August 22, 2017, 2:12pm UTC](https://forum.serverless.com/t/apig-lambda-proxy-multipart-formdata/2548/1 "2017-08-22T14:12:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![adambiggs](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/adambiggs/32/235_2.png) [@adambiggs](https://forum.serverless.com/u/adambiggs)\
**Post date:** [October 13, 2017, 9:25pm UTC](https://forum.serverless.com/t/apig-lambda-proxy-multipart-formdata/2548/2 "2017-10-13T21:25:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bbilger](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/bbilger/32/1066_2.png) [@bbilger](https://forum.serverless.com/u/bbilger)\
**Post date:** [October 13, 2017, 9:45pm UTC](https://forum.serverless.com/t/apig-lambda-proxy-multipart-formdata/2548/3 "2017-10-13T21:45:36Z")

</div>

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](https://github.com/bbilger/jrestless-examples/blob/master/aws/gateway/aws-gateway-binary/README.md))

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [October 14, 2017, 12:30am UTC](https://forum.serverless.com/t/apig-lambda-proxy-multipart-formdata/2548/4 "2017-10-14T00:30:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chicus12](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/chicus12/32/3660_2.png) [@chicus12](https://forum.serverless.com/u/chicus12)\
**Post date:** [September 30, 2019, 10:40pm UTC](https://forum.serverless.com/t/apig-lambda-proxy-multipart-formdata/2548/5 "2019-09-30T22:40:08Z")

</div>

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

> <https://github.com/bbilger/jrestless-examples/blob/master/aws/gateway/aws-gateway-binary/README.md>
