0

I have a simple Laravel app with endpoints for file upload.

When I call POST endpoint to create (and upload) brand new file, everything works on both local (docker) and AWS.

I do HTTP POST to api/file with payload:

enter image description here

I pick file from my desktop, provide name, type and model's UUID (polymorphic relationship).

However… when I want to overwrite this file I have a HTTP PUT endpoint: api/file/<UUID OF PREVIOUSLY UPLOADED FILE> with payload:

enter image description here

The issue is bizarre because I don't get any PHP issues. Laravel simply cannot pass the validation because it somehow completely DOES NOT SEE the payload on AWS. On local (docker) this works with no issues whatsoever.

I'm pretty sure this is AWS related but I'm running out of clues what is the culprit. Below is the validation message bag but I swear I pass type and model_uuid (screenshot number 2).

{
    "error": [
        "Model type is required.",
        "Model UUID is required."
    ]
}
2
  • 1
    Maybe that one can help: stackoverflow.com/questions/50691938/… Commented Jul 16, 2021 at 11:43
  • Did you try the same file for your POST endpoint on aws as well? Is there any waf setup in aws to block the PUT method or file size limit? Commented Jul 16, 2021 at 11:43

1 Answer 1

1

As far as I know, with html form standards, you can only use GET or POST for form submission. Here you are sending your form-data which is considered as a form with PUT and it is not acceptable.

So you have two options, either switch to POST or do a method spoofing that Laravel supports.

For method spoofing, make your request verb POST and in your form-data add an _method input with value PUT. Basically you are sending a POST request but Laravel request handler will assume it as PUT internally. And you can define your route as Route::put(....).

The method override in Laravel Kernel, occurs here.

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.