0

Hope you guys can help me. I'm using Uppy, with XHRUpload plugin, to upload a file but I'm getting an empty array of $request on the server side (Laravel) when I'm about to update a file using PUT request. I've tried method spoofing but still no luck. Here's my code...

I'm using uppy.setMeta by the way to add some additional data to the request.

    uppyUploader.setMeta({ 
      ...($(this).data('action') != 'store') && { _method: 'PUT' }, // Method spoofing of Laravel but the original method is 'POST'
      filename: $('input[name="filename"]').val(),
      ...
    });
    uppyUploader.upload();

but I got this in my update controller method's $request

$request->all(); // [] <-- empty array
rjcarl
  • 702
  • 6
  • 11

2 Answers2

1
  • To verify if the file is available in request you can use $request->hasFile('filename')

  • To get the specific file from request you can use $request->file('filename') or $request->filename

  • To get all files from request, you can use $request->allFiles()


For more details check Laravel Docs: https://laravel.com/docs/master/requests#files

Vaibhavraj Roham
  • 1,138
  • 11
  • 26
  • Your answer is not related to the question, I have same issue but your answer is not related to the real problem, also I did try all of them before reading your answer. – Nazari Mar 05 '21 at 14:09
  • @Nazari Answer clearly shows how you can get the file from request. Additionally I have showed how to verify if file is available in request or not. If you check the last line of question you can see how he is trying to get the file. – Vaibhavraj Roham Mar 15 '21 at 08:52
1

It turns out that it was just a caching issue on the server side. Just notes to remember, if you're using XHR, you can easily set the method to PUT, but when you are using traditional forms, you have to make sure that you spoof the method using @method('PUT') and set the form method to POST as HTML5 forms doesn't support PUT method. Thanks for helping me out. Happy Coding.

rjcarl
  • 702
  • 6
  • 11