-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.0] File upload is broken when submitting a form without selecting a file #6189
Comments
Update - check out @mantasradzevicius post of @lucasmichot 's fix below. It's more holistic and isn't based on javascript or editing core files. +1 I've been having trouble with laravel-stapler after manually migrating and setting it up. Same result if using a multipart form type. My solution is hilarious but doesn't require editing core files if you're okay with alienating non-js users:
Essentially, I remove the input if the value hasn't been set to anything. Super hacky but it might fit for someone in the interim. |
+1 |
+1 Hoping for a fix soon. |
I was about to create an issue for this too. I wrote a test case for it: In HttpRequestTest.php: public function testInputWithEmptyFilename()
{
$invalidFiles = [
'file' => [
'name' => null,
'type' => null,
'tmp_name' => null,
'error' => 4,
'size' => 0
]
];
$baseRequest = \Symfony\Component\HttpFoundation\Request::create('/?boom=breeze', 'GET', array('foo' => array('bar' => 'baz')), array(), $invalidFiles);
$request = Request::createFromBase($baseRequest);
} |
+1 |
|
+1 |
7 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
Thanks @youanden for the temporary JS fix. Works a treat. |
@alexleonard glad I could be of service. |
@youanden I used your fix, did the trick until a fix came out, thanks! I've rewritten it a little with jquery to work across all file forms:
|
+1 and +1 for marking it as important |
+1 |
As a temp solution how to apply this fix:
Example namespace App\Http;
use Illuminate\Http\Request as LaravelRequest;
class Request extends LaravelRequest
{
/**
* {@inheritdoc}
*/
public function duplicate(
array $query = null,
array $request = null,
array $attributes = null,
array $cookies = null,
array $files = null,
array $server = null
) {
$files = array_filter((array)$files);
return parent::duplicate(
$query,
$request,
$attributes,
$cookies,
$files,
$server
);
}
}
$response = $kernel->handle(
$request = App\Http\Request::capture()
);
$response->send();
Does this work: yes |
@colinyoung87 your temproary jQuery solution works perfect, thanks for that! |
@mantasradzevicius Thanks. I can confirm this worked after changing the namespace accordingly. |
@colinyoung87 Thanks for the solution. This worked perfectly. |
Perhaps it can be a Symfony problem. what do you think ? Fatal error: Uncaught exception 'InvalidArgumentException' with message 'An uploaded file must be an array or an instance of UploadedFile.' in /var/www/html/.../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/FileBag.php:59 Stack trace: #0 /var/www/html/.../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/FileBag.php(73): Symfony\Component\HttpFoundation\FileBag->set('image', NULL) #1 /var/www/html/.../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/FileBag.php(48): Symfony\Component\HttpFoundation\FileBag->add(Array) #2 /var/www/html/.../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/FileBag.php(37): Symfony\Component\HttpFoundation\FileBag->replace(Array) #3 /var/www/html/.../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Request.php(448): Symfony\Component\HttpFoundation\FileBag->__construct(Array) #4 /var/www/html/.../vendor/laravel/framework/src/Illuminate/Http/Reque in /var/www/html/.../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/FileBag.php on line 59 FileBag->set('image', NULL), receaves NULL, and that is what is dispatching a throw! ...in Symfony on the FileBag.php file, convertFileInformation method returns NULL if no files was selected on the upload. |
...without selecting a file in Laravel 5! My tests revealed that with this tweek the problem described at this issue are resolved: laravel/framework#6189 ...in Symfony on the FileBag.php file, convertFileInformation() method returns NULL if no files was selected on the upload. In this case "FileBag->set('image', NULL)" receives NULL, and that is what is dispatching a throw! I don't make unit tests, but this will no more break my code flow. I'm not sure if this is the real deal! If someone could look deeper into the problem, I appreciated! | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | no | Fixed tickets | | License | MIT | Doc PR |
...without selecting a file in Laravel 5! My tests revealed that with this tweek the problem described at this issue are resolved: laravel/framework#6189 ...in Symfony on the FileBag.php file, convertFileInformation() method returns NULL if no files was selected on the upload. In this case "FileBag->set('image', NULL)" receives NULL, and that is what is dispatching a throw! I don't make unit tests, but this will no more break my code flow. I'm not sure if this is the real deal! If someone could look deeper into the problem, I appreciated! | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | no | Fixed tickets | | License | MIT | Doc PR |
+1 |
+1 |
I have this problem using the multipartGraphQL() when testing the upload of a file! +1 |
After the recent changes (I did
composer update
a couple of minutes ago) you can't submit a form if you haveenctype="multipart/form-data"
andinput[type="file"]
and leaves the input field empty (no file selected).Link to error message.
Reproduce
1.
2.
3.
Set
debug
totrue
inconfig/app.php
.4.
Open up
app/Providers/RouteServiceProvider.php
and change themap
method to this:5.
Add the following code to
app/Http/HomeController.php
:6.
Change
resources/views/hello.php
to this:If you try to submit the form without selecting a file you will get
Uncaught exception 'InvalidArgumentException' with message 'An uploaded file must be an array or an instance of UploadedFile.'
, but if you select an image, you will get an array fromInput::all()
.Bad (temporary) solution
A solution is to remove an file arrays with a
null
value before using theSymfonyRequest::dublicate
method.Change the content of the
createFromBase
method fromto
You can now submit the form without selecting a file.
The text was updated successfully, but these errors were encountered: