How to upload file to lambda function or API Gateway?

43,182

Solution 1

I'd highly recommend using direct S3 upload using one of the AWS SDKs. AWS Lambda is best suited for processing events, not content transfers like uploads. You can check its billing and limits to make a more informed decision on if it's really something you're looking for.

Solution 2

API Gateway has added support for an S3 Proxy. This allows you to expose file uploading directly to S3.

http://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-s3.html

Solution 3

If want to upload file through lambda, one way is to open your AWS API Gateway console.

Go to

"API" -> {YourAPI} -> "Settings"

There you will find "Binary Media Types" section.

Add following media type:

multipart/form-data

Save your changes.

Then Go to "Resources" -> "proxy method"(eg. "ANY") -> "Method Request" -> "HTTP Request Headers" and add following headers "Content-Type", "Accept".

Finally deploy your api.

For more info visit: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings-configure-with-console.html

Share:
43,182
Henawey
Author by

Henawey

Updated on July 05, 2022

Comments

  • Henawey
    Henawey almost 2 years

    I'm trying to upload a file from iOS to AWS API Gateway and pass it through to a Lambda function, How can I implement this scenario?

    I can use multipart/form-data to upload to AWS API Gateway but how make input Model support binary data?

    [Edit1] moved from answer by Spektre

    Thanks For response, after a little of reading I figure out that's no way to upload file to lambda (and it's not logical because it's event based) and the only valid use case to upload to S3 and make S3 notify lambda.