https://github.com/reecerussell/aws-lambda-multipart-parser
A simple, lightweight tool to parse multipart/form-data from the body of incoming API Gateway proxy requests.
https://github.com/reecerussell/aws-lambda-multipart-parser
aws aws-lambda go golang
Last synced: 9 months ago
JSON representation
A simple, lightweight tool to parse multipart/form-data from the body of incoming API Gateway proxy requests.
- Host: GitHub
- URL: https://github.com/reecerussell/aws-lambda-multipart-parser
- Owner: reecerussell
- Created: 2020-07-07T14:36:33.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-13T19:06:01.000Z (about 2 years ago)
- Last Synced: 2025-05-13T19:10:27.883Z (about 1 year ago)
- Topics: aws, aws-lambda, go, golang
- Language: Go
- Homepage:
- Size: 50.8 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AWS Lambda Multipart Parser
A simple, lightweight tool to parse multipart/form-data from the body of incoming API Gateway proxy requests.
## Installation
Simply run this in your CLI:
go get -u github.com/reecerussell/aws-lambda-multipart-parser
## Example
Here is a example of a Lambda function handler, which expected multipart/form-data.
```go
import (
"context"
"log"
"net/http"
"github.com/aws/aws-lambda-go/events"
"github.com/reecerussell/aws-lambda-multipart-parser/parser"
)
func handler(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
// Parse the request.
data, err := parser.Parse(req)
if err != nil {
return events.APIGatewayProxyResponse{}, err
}
// Attempt to read the 'text' form field.
txt, ok := data.Get("text")
if !ok {
return events.APIGatewayProxyResponse{
StatusCode: http.StatusBadRequest,
Body: "missing 'text' field",
}, nil
}
log.Printf("Text: %s\n", txt)
// Attempt to read the file in form field 'file'.
file, ok := data.File("file")
if !ok {
return events.APIGatewayProxyResponse{
StatusCode: http.StatusBadRequest,
Body: "missing file",
}, nil
}
log.Printf("File Type: %s\n", file.Type)
log.Printf("Filename: %s\n", file.Filename)
log.Printf("Content Type: %s\n", file.ContentType)
log.Printf("Content:\n%s", string(file.Content))
return events.APIGatewayProxyResponse{
StatusCode: http.StatusOK,
}, nil
}
```