1

I am trying to send a binary file and string parameters to AWS API Gateway.

this is the mapping template that is on API Gateway POST:

{
    "imageFile" : $input.params('imageFile'),
    "purdueUsername" : $input.params('purdueUsername'),
    "description" : $input.params('description'),
    "price" : $input.params('price'),
    "longitude" : $input.params('longitude'),
    "latitude" : $input.params('latitude'),
    "category" : $input.params('category'),
}

Making a post request results in this: enter image description here

When I try this

{
    "imageFile" : "$input.params('imageFile')",
    "purdueUsername" : "$input.params('purdueUsername')",
    "description" : "$input.params('description')",
    "price" : "$input.params('price')",
    "longitude" : "$input.params('longitude')",
    "latitude" : "$input.params('latitude')",
    "category" : "$input.params('category')",
}

I am getting empty parameters. The api is not receiving the parameters I am sending through POST request.

enter image description here

How should I change the mapping template? Note: When I only try to have imageFile in the mapping template and only send binary file without extra parameters it works completely fine.

{
"imageFile" : "$input.body"
}

However, I want to be able to send other parameters beside the binary file.

1 Answer 1

2

this is how I solved the problem. I am sending the binary file in the body of the POST request and the other parameters as a header.

this is the mapping template I put on the AWS API Gateway

{
    "purdueUsername" : "$input.params('purdueUsername')",
    "description" : "$input.params('description')",
    "price" : "$input.params('price')",
    "longitude" : "$input.params('longitude')",
    "latitude" : "$input.params('latitude')",
    "category" : "$input.params('category')",
    "isbnNumber" : "$input.params('isbnNumber')",
    "imageFile" : "$input.body"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.