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."
    ]
}
Matt Komarnicki
  • 5,198
  • 7
  • 40
  • 92
  • 1
    Maybe that one can help: https://stackoverflow.com/questions/50691938/patch-and-put-request-does-not-working-with-form-data – Tania Petsouka Jul 16 '21 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? – Hisham Jul 16 '21 at 11:43

1 Answers1

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.

Mohsen Nazari
  • 1,281
  • 1
  • 3
  • 13