502 BAD GATEWAY when trying to upload files to lambda which is set up via SAM local API Gateway with HttpApi events
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
Description
There was no response in #1216 and there was a warning recommending to create a new issue. Actually this one seems to be pretty old, but for some reason it was closed a week ago. Unfortunately, provided solutions do not work in described case.
### Description:
> I tried to set
> ```
> Globals:
> Api:
> BinaryMediaTypes:
> - '*~1*'
> - '*/*'
> - 'multipart~1form-data'
> - 'multipart/form-data'
> - 'application~1octet-stream'
> - 'application/octet-stream'
> ```
>
> as well as
> ```
> Resources:
> CrudDebug:
> Type: AWS::Serverless::Function
> Properties:
> Handler: dist/api/functions/crud/index.debug
> Runtime: nodejs14.x
> Timeout: 10
> Environment: *ENV
> Events:
> HttpGet:
> Type: HttpApi
> Properties:
> Path: /crud-debug
> Method: any
> BinaryMediaTypes:
> - '*~1*'
> - '*/*'
> - 'multipart~1form-data'
> - 'multipart/form-data'
> - 'application~1octet-stream'
> - 'application/octet-stream'
> ```
>
> But no luck, still getting 502 (BAD GATEWAY) while trying to send files to this lambda.
>
> I need especially `HttpApi` type of event insteand of `Api` because the platform for which I am developing requires lambdas to process `APIGatewayProxyEventV2`. Everything been set up so far, but now I am struggling to create a lambda with the file upload and test it locally.
>
> BTW, I am trying to test file sending by putting this code into my Chrome Dev Tools:
> ```
> let formData = new FormData();
> formData.append('file', (await (await fetch(`https://placekitten.com/300/225?_=${+new Date()}`)).blob()));
> formData.append('file', (await (await fetch(`https://placekitten.com/400/300?_=${+new Date()}`)).blob()));
> await (await fetch('http://127.0.0.1:3000/crud-debug', {
> method: 'post',
> body: formData,
> // processData: false,
> // contentType: false,
> headers: {
> // 'Content-Type': 'application/octet-stream',
> },
> })).json();
> ```
> (changing headers didn't help too when there was single file; also my app is required to be able to upload multiple files at once).
>
### Steps to reproduce:
> ```
> let formData = new FormData();
> formData.append('file', (await (await fetch(`https://placekitten.com/300/225?_=${+new Date()}`)).blob()));
> formData.append('file', (await (await fetch(`https://placekitten.com/400/300?_=${+new Date()}`)).blob()));
> await (await fetch('http://127.0.0.1:3000/crud-debug', {
> method: 'post',
> body: formData,
> // processData: false,
> // contentType: false,
> headers: {
> // 'Content-Type': 'application/octet-stream',
> },
> })).json();
> ```
### Observed result:
502 BAD GATEWAY
### Expected result:
200 OK
### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
1. OS: Microsoft Windows [Version 10.0.19042.1110]
2. `sam --version`: 1.26.0
3. AWS region: local
Contributor guide
Assessment
This issue has not been assessed yet.